C# Am I able to use methods from Singletons(AutoLoaded Nodes) in other nodes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By SupToasty
:warning: Old Version Published before Godot 3 was released.

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?

:bust_in_silhouette: Reply From: Zylann

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