So I have this IInteractable that I tag some of my monobehaviours with.
The player has a trigger box attached to the front of them, and I have this little method running.
void OnTriggerEnter(Collider _col)
{
if (_col.GetComponent(typeof(IInteractable)))
{
interactObject = _col.GetComponent(typeof(IInteractable)) as IInteractable;
}
}
and then later in an update I call :
interactObject.Action()
to get the whole thing working.
Anyway, I’m having a problem, more of an annoyance really.
Every time the trigger box touches anything in the game, I get this warning:
GetComponent requires that the requested component ‘IInteractable’ is inherited or implemented by ‘objectName’.
And literally everything the trigger box touches gives this warning. The floor, the walls, the player themselves. This makes the console rather bothersome to use, even if I turn collapse on. Anyone have any ideas on how to make it not generate hundreds of warnings?
I will say, I found a solution that works, but requires a little more set up than I’d like. Just putting the box on the player on it’s own layer, say PlayerInteract, and then every object that you can interact with in the game on it’s own layer, Interactable. And then making it so PlayerInteract touches no layers except Interactable. This works, but I’m trying to see if I can just change the if statement to something else so I can avoid having to check layers all the time.