My script extends Spatial, but if it is attached to a RigidBody node it will access some of its methods. In GDScript I used the following:
rb = get_parent().get_node(self.name)
if rb is RigidBody: hasRb = true
In C# such a thing would not work, so I need to get the node as a RigidBody, so the code would look something like this:
rb = GetParent().GetNode<RigidBody>(Name);
However, the console output keeps throwing System.InvalidCastException. Trying different type casting still does not result in success.
Node rbNode = GetParent().GetNode(Name); //Getting the node as Node
rb = (RigidBody)rbNode; //System.InvalidCastException
rb = rbNode as RigidBody; //Returns null
Is there any way to make this work (or a better way, since GetParent().GetNode(Name)
is kinda ugly and is more of a workaround than a good solution)?