I've been trying to figure this out for more than a day.

The variable I am trying to access is public in the other file.

Here is the scene file. I am trying to access the script from Sprite_SpawnPoint to the script attached to Atom_Count

Here is the code

_public class Atom_Count : Label
{
    Sprite_SpawnPoint totalAtoms;

    public override void _Ready()
    {
        totalAtoms = GetTree().GetRoot().GetNode<Sprite_SpawnPoint>("Spawner/Sprite_SpawnPoint");
    }

    public override void _Process(float delta)
    {
        Text = String.Format("{0:0000}", totalAtoms.totalAtomsInShell);
    }
}_

Here are the errors shown

Thanks in advance!!! =)

Looking at the errors shown, it looks like the GetNode function calls is unable to find the node at the given path. I haven't really used C# in Godot very much, but this might fix it:

totalAtoms = GetTree().GetRoot().GetNode<Sprite_SpawnPoint>("Level_Game/Spawner/Sprite_SpawnPoint");

I think GetRoot returns the root of the tree, which is a Viewport Node, so you probably need to include Level_Game in the node path. You can view the scene tree from the remote inspector when running a Godot scene, which may help with figuring out what is going on.

Hopefully this helps!

@TwistedTwigleg said: Looking at the errors shown, it looks like the GetNode function calls is unable to find the node at the given path. I haven't really used C# in Godot very much, but this might fix it:

totalAtoms = GetTree().GetRoot().GetNode<Sprite_SpawnPoint>("Level_Game/Spawner/Sprite_SpawnPoint");

I think GetRoot returns the root of the tree, which is a Viewport Node, so you probably need to include Level_Game in the node path. You can view the scene tree from the remote inspector when running a Godot scene, which may help with figuring out what is going on.

Hopefully this helps!

Thanks, that solved the issue. =) =)

3 years later