Godot Version
4.6 stable Windows 11
Question
I’ve implemented a system to change between different scenes ingame, but when that happens, if there was a projectile created by the player’s weapons on the scene tree, it just freezes. The way I did it is that the player scene gets reparented to an autoload, and then when the new scene is ready the player scene is reparented to it. All the player’s weapons create projectiles by adding them as child to the current stage node, and the only functions in the projectile code are ones that only run when they collide with an enemy.
This is my function to change stage:
func change_stage(stage : String) -> void:
print("trying to change stage")
PlayerDB.PLAYER.process_mode = Node.PROCESS_MODE_DISABLED
print("player is paused")
PlayerDB.PLAYER.visible = false
print("player is not visible")
WaveManager.is_first_stage = false
print("is no longer first stage")
SceneManager.next_scene = PlayerDB.StageDatabase[stage]["directory"]
print("next scene: ", stage)
PlayerDB.PLAYER.reparent(SceneManager)
print("player is reparented to scene manager")
get_tree().change_scene_to_packed(SceneManager.loading_screen_scene)
And this is the code in my loading screen scene:
extends TextureRect
var progress : Array = []
func _ready() -> void :
print(SceneManager.next_scene)
ResourceLoader.load_threaded_request(SceneManager.next_scene)
get_tree().paused = true
func _process(delta: float) -> void:
print("is processing")
progress.clear()
ResourceLoader.load_threaded_get_status(SceneManager.next_scene, progress)
$Teacups.rotation += 0.4 * delta
$ProgressText.text = str(int(roundi(progress[0] * 100))) + "%"
if progress[0] >= 1 :
var packed_scene : PackedScene = ResourceLoader.load_threaded_get(SceneManager.next_scene)
get_tree().paused = false
get_tree().change_scene_to_packed(packed_scene)
When the freeze happens, the loading screen scene’s _ready function runs, but the _process doesn’t run at all. I don’t know what code could be causing the freeze. Any help is appreciated.