|Topic was automatically imported from the old Question2Answer platform.
I made two scenes, one with a door and some tiles - lets call this scene Main. That door, when activated, changes the scene and brings the character into another scene with another door and some tiles - lets call this scene House. In Main, when I first start, I spawn far from the door, which is how I set the scene up. I go through the door in Main, and appear on the door in House which is where I placed the character in the scene.
Here’s the problem.
When I go back through, I want to reappear where the door is in Main, but instead I appear in the starting position, far from the door.
I’ve seen many things about PackedScene having functionality similar to what I want here, but even after reading the docs I can’t figure a way to implement them.
I need an easy way to save the state of every instance under Main so I don’t want to save the position of everything in a global variable, because that would make for some very messy code and I may need to save more things for every instance, such as ammo or chest opened states and such. If PackedScene is the way to do this, I would very much appreciate a detailed explanation on how to use them because I don’t really understand them.
Thank you so much in advance!
I found an answer to this by having the doors teleport me within one scene. It works well, but it doesn’t feel like I actually solved the problem. Any help would still greatly be appreciated!
Panda_Scientist | 2020-07-08 15:47
You could consider adding alternative spawning locations to your scenes…
In other words scene internal coordinate variables which you can set your ‘players’ coordinates to when loading the scene.
entryPointA = Vector3(<some coords>)
entryPointB = Vector3(<some other coords)
And call the one you want in the
func ready(): function.
But when dealing with more variables or loads of entry points packed scenes or global variables may be more useful.
Arandual | 2020-07-08 19:07
That does seem like a very viable option, thank you for that! If I change it back to separate scenes for each area then I will definitely try that.
One thing that I would like to happen is the entire scene get saved, so all of the states for all of the instances stay the same, so even placements of enemies and other objects stay in the world where I left them. Your suggestion is an interesting concept and certainly solves the problem of spawning at the right door, though.
Panda_Scientist | 2020-07-08 19:43
My suggestion works well for a small amount of specific things, but if you really dynamically want to save enemy positions and the like then this would very quickly become a chaotic mess.
Still I am happy I could contribute at least a little!
Unfortunately I do not really have experience with packed scenes or saving such things dynamically, but I wish you the best still.
Arandual | 2020-07-08 20:18
Oh that’s OK! Talking with you was a pleasure. Hopefully we can find an answer to this problem soon because it seems like something that could be very useful in future projects. It seems like something that would be pretty easy to do but it’s just kind of not.
Panda_Scientist | 2020-07-08 20:44
Thank you for your kind words, good luck on your quest to find a solution!
Arandual | 2020-07-09 11:48