I am currently trying to catch a signal in my Area3D Node. I therefore created a method in my Area3D called public void _on_body_entered(Node3D body) as suggested by the documentation. I linked the signal of the Area3D body_entered to my internal on_body_entered method by using the GUI. Now however I am clueless why the typecast for the signal doesnt seem to work.
Whenever my player enters the area the signal gets correctly redirected to my method. However the typecast from RigidBody3D to Node3D doesnt seem to work.
Isn’t RigidBody3D automatically upcasted to its base class Node3D?
Method recieveing the signal:
public void _on_body_entered(Node3D body)
{
GD.Print($"Body entered: {body.Name}");
}
Error when player RigidBody3d enters the Area:
E 0:00:20:0783 object System.Runtime.CompilerServices.CastHelpers.ChkCastAny(System.Void*, object): System.InvalidCastException: Unable to cast object of type 'Godot.RigidBody3D' to type 'Node3D'.
This is just a small tip but in my opinion, if you use C#, you’re much better off using C# events built into Godot rather than signals. They’re a lot more friendly when working with C#, much more readable as well, and easy to deal with.
And my previous post contained the answer. The Game designer accidently created a blank Node3D and attached a script to it. This created a Node3D.cs file he immediatly closed (and saved).
This created the following problem:
All refrences with out the Godot namespace declared referenced this Node3D script now instead of the actual Godot.Node3D. Deleting that empty script fixed all issues.
Is there a setting which lets me add a default Pre / Suffix when a script name is automatically created? I want to make sure that this does not happen again.