- Home /
collider trigger or scripting
What's better for performance?
Use a collider with a trigger or use an array and check the distance or something and starts an action?
Thanks for the replies.
I am trying to get GC alloc a low as possible. If I use a collider with a trigger with a simple function in TriggerStay it cost directly GC Alloc(few kb) for each loaded object.
I also try to get the same affect with scripting. I put all the neccesarry objects in a list/array. Start a function when the distance is low enough.
When i got a lot of moving ojects thats reacts with each other. What is a common way to to handle them?
Answer by Berge · Apr 21, 2015 at 11:59 AM
Raycast will give you more accurate selection of which object you want to trigger an action on. (you can point at an object with a ray and check distance, and get info about the object the ray hits etc..) Triggers would be better for preformance, but won't give you the same accuracy.
https://unity3d.com/learn/tutorials/modules/beginner/physics/raycasting
Answer by ShabihDesperado · Apr 21, 2015 at 12:00 PM
If you check only the layers you need in project settings -> physics you will get a nice performance. If you make your own script will depend how good programmer you are.
Answer by Kire · Apr 22, 2015 at 01:11 PM
I found the problem. I did all de debugging with the editor. When I use the profiler on the phone the gc alloc disappear. I read on a forum that get component is zero, create gc alloc when the profiling is set on the editor.
Your answer
![](https://koobas.hobune.stream/wayback/20220613193650im_/https://answers.unity.com/themes/thub/images/avi.jpg)