0 votes

I want to call a method from an auto loaded node's c# script from the current running scene's c# script. I tried calling the method using GetRoot().GetNode("AutoLoaded Sibling to current scene").my_method();, like I would when using GDscript, but that didn't work. I also tried calling the class name of the node then the method...this didn't work either. Has this not been implemented yet, or is there a c# way of doing this?

in Engine by (246 points)

1 Answer

0 votes

Could you post the errors you get?

From my guess, GetRoot().GetNode("AutoLoaded Sibling to current scene").my_method(); is not going to work because unlike GDScript, C# is statically typed, so you must cast the node before using your method, like:

MyNode node = GetRoot().GetNode("AutoLoaded Sibling to current scene") as MyNode;
if(node != null)
    // Uh, the node could not be found or is not a MyNode
by (29,034 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.