I’m using Godot 4.5. My question: how do I properly instantiate scenes dynamically and efficiently while making sure they’re already ready when they need to be? When and where should I use await?
I was doing some coding and hit a null reference error, and after hours of debugging it magically started working and I’m not sure what I did. At some point in there I tried await and ended up in infinite loops waiting for scenes that were already ready. I ended up removing all of the await statements and everything magically started working.
@rpahut: no, I didn’t need await. I’ve continued programming in the last 4 days with no further issues of this kind after having removed it. Right now the game is small so everything seems to happen instantly. Eventually I might need to figure out when things get loaded and where to do it in advance so that the game never pauses for loading when it could have loaded stuff in the background. I may never get there as the game is turn based anyway.
@normalized: I meant a scene that has children by default with a script that dynamically instantiates one or more scenes, and then any of those children also dynamically instantiate scenes.
If all that instantiation happens in _ready(), it should be fine as parent’s _ready() always runs after all of it’s children _ready()s have been executed.
There may be problems if you have inter-sibling _ready() dependence though.