Godot Version
4.3
Question
So I am a bit into the Tower Defense project that I am doing experimenting with Spawners, Enemies and Towers but I haven’t truly begin setting up the hierarchy of the project. For example I gave a Control Node - MainMenu which runs as the main scene. Then I have a level select scene which is also a control node and it has two buttons for Level 1 and Level 2.
Now the Level 1 which I did was made onto a Node2D GameScene which also has the other needed nodes like UI, Spawners, Towers and more.
But when I try to load the Level 2 from the level select it just runs the Level 2 scene but without the GameScene which has a lot of the functionality scripts.
I know that I am going around it in a wrong way and I would like to hear your thoughts on how it could be done better?
Should I try to run the GameScene from the LevelSelect window and then somehow try to instantiate the levels which are chosen as children of the GameScene which will have the needed functionalities.
Because if I load the Level Scenes I will need to use the same code over and over in every level scene to have the wanted result but that would be quite a bad way to go around it I think.
What does your scene tree for level 1 and level 2 look like? What happens when you run level 2 with F6 (run current scene)?
If you are using change_scene_to_file
it will remove everything in the scene tree except Autoloads.
Not at home right now to send a screenshot of it but wait I will just writhe the hierarchy here.
Level 1 is saved like this
GameScene
Level1
MAP
WaveSpawner
Towers
Castle
UI
Now for Level 2 it loads
Level2
MAP
WaveSpawner
Towers
Castle
UI
The LevelSelect Scene has the links to both of these levels but only for the first level it loads up the GameScene. Now I think that I need to try to instead of loading the levels to first load the GameScene and afterwards try to load the levels by instantiating them but the ways I tried to do that it always crashed. Because I think I will be doing a mistake if I save multiple Levels with the GameScene as different scenes.
And yeah I was using that command to load
I think Level 1 is a better format. To speed up this process you can make a base scene with GameScene, WaveSpawner, Towers, Castle, UI then right click it and select “New Inherited Scene” for each level.
After coming home and going back and forward with some tutorials and even a bit of chat gpt for some detailed explanations I managed to cook up a SceneManager which does the change_scene_to_file function basically but first instantiates the GameScene, loads the Level chosen and destroys the last scene. It may need a bit of more work to fine tune it but I hope it’s going to be good going forwards.
For the hierarchy I will now always have a BaseScene Node which will always hold the different components while always swapping out the children if needed. Need to do some further research and experimentation to get the finer details and also read even more of the documentation. Was reading everything for the “dir” funtions since I want to also get a dictionary which holds the level information and loads it dynamicaly so I escape the hardcoding in my game.
Thank you for the tip of Inherited Scenes as well I also did some research on it and I may even use it they way You mentioned but I will need to experiment a bit to see how it would work since some aspects have to be reused but have different positions and functions, but if it works it would make a lot of things way easier.