Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Panzer0312 |
In my 2D space game I’m instanciating a generated system-scene when the player-ship enters a specific area and add it to the world node. Once the player leaves this scene by moving to a specific distance I remove the scene and set the player’s position to it’s entering position (previously saved by a singleton).
(this way I can open and close systems from the game-world pretty easy without losing important references)
There are 2 possible outcomes:
→ when I add print(String(singleton.player_ship.global_position))
after setting it’s position it works
→ when I don’t add it, setting it’s position to it’s entering position doesn’t work
This kinda confuses me a lot
Does anyone know why this problem might occures?
A print statement shouldn’t affect your code. Can we see the rest of your code?
exuin | 2021-04-17 22:00
Sure
I might have overused singletons (GameManager,ObjectManager and SceneManager)
So when I comment out the last print statement the ship stays at it’s position
func _process(delta):
if (ObjectManager.player_ship.position-GameManager.selected_system.rect_position).length() > world_length and !exit:
print("exiting system")
exit = true
ObjectManager.player_ship.global_position = GameManager.ship_entering_position
print("ship position: %s" % String(ObjectManager.player_ship.global_position))
SceneManager.close_system()
I use exit as bool so I’m sure it only get’s called once,world_lenght is just an int and SceneManager.close_system() calls remove_child(system_scene)
Panzer0312 | 2021-04-17 22:18