- Home /
Box Collider (Trigger) Efficiency Question
Hey all,
I have a question about the efficiency of trigger box colliders. And more specifically, I don't want an answer such as: 'it's quite efficient'. I'd like to know roughly how many calculations have to be done and how often - and if you don't know exactly, then a good estimate works for me.
So, say I have one box collider (a trigger) set around the world in various places. And say I set it to collide with ONLY the player, and nothing else using the collision matrix.
Also, let's say it's not static because I don't think static will work for what I need.
How many calculations are happening? Is it doing constant per-frame calculations to try to detect a collision? I imagine it has to do calculations rather frequently (every 'physics time step' perhaps?) so that it can know when there's a collision.
And how computationally expensive is such a calculation? Any other calculations that happen?
Finally, are any of these calculations happening on a thread that isn't the main thread, or on the main thread?
Note: I'm not talking about calculations that happen when an actual collision occurs. I'm only talking about calculations assuming the player isn't colliding with them and they're just in the world near the player.
Thanks in advance if you can help.
constant per frame calcs, impossible to say how many calcs are happening totally dependent on your game, but assume it is "a bunch", individually they aren't t0o expensive but as a whole the physics stuff can be 20-30% or more of profiler-reported game thread time; physics on their own thread; any other calculations that happen - yes, a ton hard to quantify dependent on your game.
Once your game is out of design and you have some solid code base, consider using your Unity 30 days pro trial to make use of the Unity profiler to get a real view of your game and where its spending its time.
I guess I should have rephrased it. I'm mainly thinking about just one collider. How does it depend on my game? If I have one trigger collider that isn't colliding with the player, how much work is it doing? I'm not sure what other factors would influence this.
Yes, I have pro and I can use the profiler, but I'm looking for details here on a level the profiler probably wouldn't be able to help me with (or because it would require me to do a bunch of work that I shouldn't have to do if I can get an answer here), so I can make a proper decision with what I'm about to do.
Your question speaks in plurals (colliders, triggers, around the world in various places, etc) but your follow-up says ONE collider. Well those are the things that make physics performance dependent on the game (i.e. how many).
If you have Pro and the profiler, I'm really lost.
Hence the 'guess I should have rephrased' part. Okay, I edited the post to make that more clear.
The thing is, I have two choices going forward. I can use trigger colliders to do what I want to do or I can use another method. I'm not sure which one is going to hurt the FPS the most.
Both will take a good amount of time to do, so I figured I would come here and ask about the calculations involved with colliders. Having this information would tell me which one would perform the worse.
Using the profiler would require I go through and make both and compare them, which is a lot of work when I could just ask this question.
Probably could have done it by now! But I've been busy doing course work, anyway.
Your answer
Follow this Question
Related Questions
Is there a way to deny an exit (and therefore OnTriggerExit) 2 Answers
How to enable the box collider tick box on a trigger event 2 Answers
Collider/trigger collision causing physics glitch 0 Answers
overlapsphere to destroy NPCs on exit 1 Answer
Collider Lifts me off Ground ??? And I'm afraid of heights !!! 1 Answer