0 votes

I've been following the tutorial on changing scenes asynchronally (as seen here) and translating it to C#, however, the following errors occur:

  1. E 0:00:01.799 get_tree: Condition "!data.tree" is true. Returned: nullptr
  2. E 0:00:01.802 connectsignalawaiter: Parameter "p_source" is null.

When yielding, I run

 await (ToSignal(GetTree(), "idle_frame"));

as seen here
however the errors above happen right at that moment. What am I missing to properly load resources/scenes asynchronously?

Code:

   private async void ChangeSceneAsync(string path)
{
    ResourceInteractiveLoader ril = ResourceLoader.LoadInteractive(path);

    while (true)
    {
        Error err = ril.Poll();
        if (err == Error.FileEof)
        {
            Resource res = ril.GetResource();
            break;
        }
        if (err == Error.Ok)
        {
            float progress = (float)(ril.GetStage() / ril.GetStageCount());
            GD.Print(progress);
        }

        await (ToSignal(GetTree(), "idle_frame")); // Errors occur here
    }
}
Godot version 3.4.2
in Engine by (41 points)

1 Answer

+1 vote
Best answer

I got this error once and the reason was that the node (where the script is running the GetTree()) was not inside the tree. You need to make this node a child of another. Another reason might be that you are using the constructor of this class instead of using the _Ready method.

by (243 points)
selected by

This was it. I had this function in an autoloaded Global.cs script thats why it couldnt find the tree.

I moved it to a node in a simple scene to test it quickly and now it loaded my resource properly.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.