Queue_free freezes game

Godot Version

Godot v4.2.2.stable.arch_linux

Question

Hi there, I got my game freezing when changing a part of my scene tree. I got a transition running during that loading time using an animationplayer(also tried _progress in one script - same result).

The animation player is basically controlling an alphavalue for a shader getting from 0 to 1 in a short time.

I got the bug down to a part of my functions:

I am connecting the signal of when the main part of the level is unloaded:

"

levelnode.tree_exited.connect(load_new_level)

"

Then I am calling this function:

"

func unload_level() → void:

print(“LEVEL IS UNLOADED”)

onload nodes under %Worldviewport
if (is_instance_valid(levelnode)):

levelnode.queue_free()

%Transition/AnimationPlayer.play(“fade out”)

levelnode=nul

"

%Transition/AnimationPlayer.play(“fade out”) ← calling the fading animation which is not seen until after the freeze. I can put

await get_tree().create_timer(X).timeout

to see X seconds from my animation before the freeze. Freeze is about 1-3seconds. I don’t care that the game loads for 1-3seconds. Does not matter. But the Animation should not pause/freeze during that loading time.

So how to unload part of my level and still have my transition playing while doing it?

You can’t queue freeing it before you’re done with it, it’ll be freed at the end of the frame, instead make it call some finishing method at the end of the animation, or wait for the animation to end

Thanks for reading and giving it a shot.
The animation is NOT a part of the nodetree that is queued free. It freezes for 2-3seconds and runs fine afterward
ROOT
|-level
|-animation
|-other stuff
only level is queued free.

try load new level first, then free self