Exclude OnTriggerStay with certain objects

Hello, I have this simple logic for some AI processing.
The logic checks for the object that is inside the trigger to see and only do processing if it is the player.
It worked very well on PC, but when I ported that to a mobile platform it was too slow.
When I used the profiler I can see that about 80% of time in OnTriggerStay, even if player is not inside the trigger.
How can I prevent trigger physics calls from working except when the object is the player?
I tried the collision matrix from Project Settings->Physics, but it did not work with triggers.

void OnTriggerStay (Collider other)
{
		// If the player has entered the trigger sphere...
        if(other.gameObject == player)
        {
            ...
        }
}

Thank you very much for advance.

1 Answer

1

You want to try layer based collision detection. Put the player on a separate layer, and have the trigger on a layer that only checks for collision against the player.

Thank you, for some reason I did not notice that I was colliding with the default layer.