I've written an asynchronous method (in C#) to handle screen transitions. After reading the docs for SceneTree, I thought it would be a good idea to wait for the frame_idle event to be fired after changing a scene to make sure my new scene is loaded before trying to access it. Trouble is, this signal does not seem to be fired. When I run the below code, the last thing printed to console is <5>
and my fade in method is never called. What's going on? What's the right way to ensure a scene is loaded before trying to access it?
void onBodyEntered(Node body)
{
if (body is Ball)
{
Fader fader = GetNode<Fader>(Fader.AUTOLOAD_PATH);
SceneTree tree = GetTree();
Task.Run(async () =>
{
GD.Print("<1>");
await ToSignal(tree, "idle_frame");
GD.Print("<2>");
await fader.fadeOutAsync();
GD.Print("<3>");
await ToSignal(tree, "idle_frame");
GD.Print("<4>");
Error result;
if (targetScene == "")
{
result = tree.ReloadCurrentScene();
}
else
result = tree.ChangeScene(targetScene);
GD.Print("<5>");
await ToSignal(tree, "idle_frame");
GD.Print("<6>");
await fader.fadeInAsync();
GD.Print("<7>");
});
}
}