#Exported PackedScene Variable becomes null in the child of an instantiated scene.
24 messages · Page 1 of 1 (latest)
Oh and if you know a better way to do room transitions or a room system in general please let me know.
so does that mean that the next room also has a room transition node which contains the previous/current room as an export variable?
Yes. (sorry for late response)
It could also contain another room as an export variable, and a room could also have multiple transition nodes.
Hm. I wonder if it's a circular dependency issue.. If you make the other room go to a room other than the original room, does it still come up null?
I just tested it, and it seems to work for exits to rooms that you haven't entered yet, since if you go to a third room and then try to go back to the original room, it still doesn't work.
Hope that helps.
I also found this.
It seems that there is a very small window of time where both the room you are entering and the room you are leaving exist simultaneously.
That still doesn't explain this.
That sounds like a circular dependency thing. When a scene tries to load another scene in one of its variables, if that other scene contains the first scene it can cause issues, and that can also happen with larger loops like you described here. One way I've tried to work around this is having some kind of manager that holds a reference to all of the level scenes in a dictionary with the keys being strings, so when setting what scene an exit goes to I set a string instead of a packedscene, and when it tell it to change levels it uses the string to pull from the dictionary.
That avoids a circular dependency, because none of the scenes actually contain references to the other scenes
Could you have the scenes contain references to the file paths of other scenes?
And then load those scenes in the room manager?
You could, but using a separate manager allows you to preload the scenes instead of loading them at runtime, which can reduce loading times
Since you already have a Room Manager, that's a good candidate for this kind of thing
What is preloading?
You know how to use load()?
preload() is a different thing that also loads resources from the file system, but it does it immediately upon the game starting, instead of when the actual call is reached, so there's no time spent loading the resource during gameplay.
Thanks so much!
the question would of course be if you have enough memory to have all rooms preloaded inside the manager.
That's a problem to face when it comes up, I think. But there are definitely ways around that too. Like swapping from a dictionary of names to scenes to a dictionary of names to file paths, and using load() when a scene is requested from the manager.