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?

asked Nov 17, 2017 in Engine by SupToasty (241 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)
    node.my_method();
else
    // Uh, the node could not be found or is not a MyNode
answered Nov 17, 2017 by Zylann (27,006 points)
edited Nov 17, 2017 by Zylann
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.