Godot Version
v4.6.2
Question
Hi, I’m new to Godot and programming as a whole so I wanted to consult some people who were a bit more experienced to figure out how I should handle this.
I’m created a grid-based ecosystem game where you can choose which animal you’d like to be and so far it’s going pretty well. The problem I keep encountering, however, is that some things get loaded in before others, for instance:
My game would load my menus then my main scene and then add my player into it.
My problem came with the health bars, which were added alongside the main scene and freaking out because they couldn’t see the player’s health components and saying values were null (which were added a few seconds later with the player). Even when I added the healthbar to the Player scene it returned null - that stumped me for a day or two. Finally I added a signal that, after the player had been added as a child to the main scene, would emit that “player was ready” and that’s worked great so far - the only annoying thing being that I have to add it to the ready function of literally anything trying to interact with something that hasn’t been ‘created’ yet.
I have a few questions:
- Is there a way around this / is this bad practice (regarding the ‘player ready’ signal)? Is there an easier way than doing what I’m doing? I just started working on a FoodSpawner script for the food in the ecosystem and am running into some issues trying to access a TileMapLayer on the main scene that hasn’t been loaded yet.
- Should I instantiate my world from the launch of the game and pause it while the player is in the menus or should I only instantiate after they’ve selected their character and pressed start?
- If I instantiate at character select, how do I access nodes that ‘don’t exist yet’?