- Home /
Is too many trigger colliders and function calls very bad for game performance?
I am making a karting game and for the positioning system, I am using about 400 trigger colliders placed very close to each other around the track, and everytime the player or opponent enters one of them, a value increments in their script. Then every 0.2 seconds, a function call happens in the race manager script, which sorts a LIST (not array) of references (scripts) to each player/opponent, according to that value being incremented in the race. The index+1 of every player in the list represents their position. The positioning system works fine, and I am testing it with 3 players currently. I did not notice any frame rate drops when testing the game, but I was wondering if this is a bad idea and if I should go for another solution. Earlier, I tried the three way sort method where it first tries to organize players by lap they are on, then by the value I described, and then by the distance to the next checkpoint if two players are on the same upcoming checkpoint. I avoided this because I heard that vector3.distance can be expensive if called too much.
Answer by Magso · Jul 10, 2020 at 04:30 PM
"400 trigger colliders placed very close to each other around the track, and everytime the player or opponent enters one of them, a value increments in their script."
I also used to do this and yes the performance will suffer. You're better off using only a few waypoints and using the Vector3.Distance
method, multiply the returned number by the waypoint number and sort the array lowest to highest.
Oh, ok. Is the method call to the OnTriggerEnter very heavy? If so, then I will change the method I use for positions
Because I was having issues with the vector3.distance comparison thing. I just used this method since it is an easy way to do it. However, I will revisit the vector3.distance method and try to make it work.
Vector3.Distance isn't heavy, it's returning a length of a vector as a float as opposed to OnTriggerEnter which is using physics to return a collider type.
Edit: technically OnTriggerEnter returns void, the collider is the parameter given by the physics engine.
Your answer
![](https://koobas.hobune.stream/wayback/20220613002909im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Why Trigger colliders costs more than non trigger ones? 0 Answers
Make an object a trigger? 1 Answer
What is the trigger? 2 Answers
Build and Run is breaking my triggers! 1 Answer
Some problems with triggers? 1 Answer