- Home /
Is there any way to see exactly which triggers are overlapping?
I'm suddenly getting enormous spikes in my trigger overlaps, (according to the profiler) and I can't imagine why. Everywhere else in my level, the overlaps stay below 1k, and usually only 300 or so. But in a specific section, it spikes up to 2.6k, then later 3.6k, causing a lot of lag (I'm assuming it's the cause, since they happen at the same time). And there's only like 5 alive people in the level at the time, and a bunch of corpses (40+ people in a test scene runs great, even when they're all fighting each other, and under 300 overlaps)(also, ~100 corpses in the test scene ran really nice too, even less overlaps, so it's not them).
My main question here is: Is there any way to figure out what object(s) are causing these crazy overlaps? I feel like that would solve this. Any other suggestions are of course welcome.
Another related side question I had was whether a trigger needs to have some sort of OnTriggerEnter() / OnTriggerStay() etc attached to it to count towards the overlaps, or does it count regardless?
Answer by bpaynom · Mar 06, 2019 at 09:17 AM
I don't actually know if there is a direct way to get it, but something i would try if not is this: In some script.
public bool checkOverlaps = false;
private void Update()
{
// You manually change it from the inspector when you want to check overlaps
if( checkOverlaps )
{
checkOverlaps = false;
CheckOverlaps();
}
}
private void CheckOverlaps()
{
Collider[] colliders = FindObjectsOfType<Collider>();
foreach( var col in colliders )
{
col.isTrigger = false;
col.gameObject.AddComponent<CheckContacts>();
}
}
Then, use this script:
public class CheckContacts : MonoBehaviour {
private void OnCollisionStay( Collision collision )
{
foreach( var c in collision.contacts )
{
Debug.Log( name + " collides with " + c.otherCollider + " at " + c.point + " point " );
c.thisCollider.isTrigger = true;
Destroy( this );
}
}
}