- Home /
Item pickup, OnTrigger vs Raycast? Which is best?
Does it matter which you use? Is one more optimized for this behavior?
I think you are asking in terms of CPU efficiency, correct? So ins$$anonymous$$d of raycasting and iterating through a list of objects hit, you would just like to use the OnTrigger functions ins$$anonymous$$d? If thats the case, I would like to see an answer for this question as well.
Yes, for items on the ground, you walk up to them and pick them up. Either using raycast to trigger when looking at them, or using ontrigger so that when within the collider area, you can pick it up, and doesnt matter if you are looking at it.
Answer by Owen-Reynolds · Jan 23, 2013 at 03:45 AM
The two methods give different end results, so use whichever gives the effect you like.
Triggers will work even if you back into it with someone else in-between. A rayCast would make sure you can see it (for example, it's next to a wall and you can't grab it "through the wall") and might be an easy way to make sure you are "looking" at it.
Answer by justinl · Apr 19, 2013 at 03:36 AM
I've tried this using Raycast and Physics.OverlapSphere and OverlapSphere was vastly faster. Once I started having 100's of items the Raycast eventually would cause a large spike in my fps on the Profiler and the game would studder. After switching to Physics.OverlapSphere the spike was gone.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091425im_/https://answers.unity.com/themes/thub/images/avi.jpg)