diff --git a/Scenes/MainScenes/Game.cs b/Scenes/MainScenes/Game.cs index 57fe6a9..35ab7c4 100644 --- a/Scenes/MainScenes/Game.cs +++ b/Scenes/MainScenes/Game.cs @@ -54,12 +54,12 @@ public override void _Ready() //else cslogger.Error("WTF - map canvas layer"); serverConnection = new ServerConnection(); - this.AddChild(serverConnection); + this.CallDeferred("add_child", serverConnection); PackedScene packedLoginScene = (PackedScene)ResourceLoader.Load("res://Scenes/LoginScreen.tscn"); loginScreen = (LoginScreen)packedLoginScene.Instance(); loginScreen.Visible = false; - this.AddChild(loginScreen); + this.CallDeferred("add_child", loginScreen); loginScreen.Visible = true; // TODO: check for server connection and do some retries if something is wrong @@ -147,7 +147,7 @@ void updateGameRadar() newBlip.Texture = shipBlip; newBlip.Offset = new Vector2(finalX, finalY); - gameRadar.AddChild(newBlip); + gameRadar.CallDeferred("add_child", newBlip); } } @@ -230,7 +230,7 @@ public PlayerShip CreateShipForUUID(string uuid) shipInstance.uuid = uuid; _serilogger.Debug("Adding ship to scene tree"); - AddChild(playerShipThingInstance); + CallDeferred("add_child", playerShipThingInstance); // TODO: this is inconsistent with the way the server uses the playerObjects array // where the server is using the ShipThing, this is using the PlayerShip. It may @@ -326,7 +326,7 @@ public SpaceMissile CreateMissileForUUID(GameEvent egeb) missileInstance.GlobalPosition = new Vector2(egeb.PositionX, egeb.PositionY); missileInstance.RotationDegrees = egeb.Angle; _serilogger.Debug("Game.cs: Adding missile to scene tree"); - AddChild(missileInstance); + CallDeferred("add_child", missileInstance); // just in case we need to use it later missileInstance.AddToGroup("missiles"); @@ -395,7 +395,7 @@ void CreateLocalMissileForUUID(string uuid) missileInstance.Position = missileInstance.Position + offset; _serilogger.Debug("Game.cs: Adding missile to scene tree"); - AddChild(missileInstance); + CallDeferred("add_child", missileInstance); // Run the missile animation _serilogger.Debug($"Game.cs: Starting missile animation for {missileInstance.uuid}"); diff --git a/Scenes/SupportScenes/PlayerShip.cs b/Scenes/SupportScenes/PlayerShip.cs index 03ff454..7c312c3 100644 --- a/Scenes/SupportScenes/PlayerShip.cs +++ b/Scenes/SupportScenes/PlayerShip.cs @@ -134,7 +134,7 @@ public void FireMissile() MyMissile.AddToGroup("missiles"); Node rootNode = GetNode("/root/"); - rootNode.AddChild(MyMissile); + rootNode.CallDeferred("add_child", MyMissile); _serilogger.Debug("Added missile instance!"); }