Hey everyone!
I want to make a battle simulator. In a mani menu I will give the user options to adjust armies size, terrain, etc.
Then I want to launch a fight (in a separate battle scene).
So the battle scene have to be heavily modified before it is loaded.
I found two ways to change scenes, and both have problems.
First one is to use something like
GD.Print(GetTree().ChangeScene("res://BattleScene.tscn"));
However, this way I cannot modify the scene before it is loaded, as it is stored in a file.
Alternatively, I loaded a packed scene and modified it somehow:
PackedScene batllescene_packed = (PackedScene)GD.Load("res://BattleScene.tscn");
battle_scene = (BattleScene)batllescene_packed.Instance();
//modify the scene somehow
Now I have to switch the scenes; I do it with
GetTree().Root.AddChild(battle_scene);
However, when I do it, the menu scene is still visible underneath the new one!
I guess I have to unload it, but when I do it, the program exits. I tried to unload the menu in two ways:
GetParent().RemoveChild(this);
And, more complicated:
MainMenu main_menu = (MainMenu)GetTree().Root.GetNode("MainMenu");
GetTree().Root.RemoveChild(main_menu);
I have been stuck on this problem for hours; what is the correct way to solve this? Much thx.