Godot Version
4.1.2
Question
Hi, I’m still not great with Godot but I’m getting there (hopefully!). I used to develop in Unity, so this question relates to the GetComponent concept from there. Essentially, what I want to do is when two bodies collide (in this case an arrow and another object that I call an Interactable) I want to use data from the Arrow script in the other Interactable’s script to apply a certain effect. Problem is, I can’t figure out a good solution that isn’t really slow. With unity, you would just use something like arrow.GetComponent().value in the collision, but I’m struggling to find a good counterpart in Godot. I’m using the GetNode function right now with the name of the arrow to get the Arrow node, but that seems clunky and wrong. If there’s a good way to do this, let me know!
This is what I have currently for the Interactable script, to make it a bit clearer:
public void OnBodyEntered(Node body)
else if(body.IsInGroup("arrow"))
{
// ApplyEffect takes an integer id as a parameter
ApplyEffect(body.GetNode<Arrow>(body.Name.ToString()).id);
}
}