- Home /
Detecting Input on ~100 Objects
Old Setup: 100ish objects with sphere colliders and non-kinematic rigidbodies that moved almost exclusively through physics interactions. New Setup: 100 odd objects that are moved through code (not physics) but need to all detect input from the user. These objects still move often. The 100ish objects in the old setup still exist and roughly inform the movement of the new 100 objects.
My old input code utilizes raycasting from a touchpoint through to an object's colliders. What's the most performant way to capture input on the new objects, instead of the old?
To be clear - the new 100 objects do not have a collider or rigidbody right now because they don't really need one. To avoid rewriting my input code, I'm considering attaching a kinematic rigid body and sphere collider to each of the new objects. The potential problem? Double the colliders and double the rigid bodies. Physics is already showing up as a hotspot in my mobile performance, I can't risk making this worse.
The question is, how much more of a hit am I going to take by creating 100 kinematic rigidbodies and colliders? I would imagine a kinematic rigidbody isn't even close to as expensive as a non kinematic rigidbody.
If it is expensive, what's my best method of detecting input on the new objects? Triggers? Kinematic rigidbody triggers? Some weird combination of something I haven't considered?
Remember, the old 100 objects that are rolling around the scene still need to exist and calculate.
Answer by LessThanEpic · Jan 27, 2015 at 11:02 PM
I use the MonoBehaviour.OnMouse---() functions (don't let the mouse part confuse you, they work on touch screens too). The performance on this has been pretty good, I'm guessing Unity does some optimizations behind the scenes that makes it faster than doing your own raycasting.
I read that having a collider but not a rigidbody marks that object as a static collider and is thus very expensive to move around. That's why I brought up kinematic rigid bodies. Can someone confirm that is true?
I stand corrected. Apparently the static collider thing is true.
http://answers.unity3d.com/questions/180210/unity-creating-static-colliders.html
I hadn't heard about that before.
Answer by DanSuperGP · Jan 27, 2015 at 11:18 PM
You're going to want to use kinematic rigidbodies and colliders detecting raycasts. That's simply the best way to do it.
So adding 100 kinematic rigidbodies and 100 colliders on top of 100 rigidbodies and colliders isn't going to have a significant performance impact?
Doubling the number of objects in your scene is going to have a performance impact...
You doubled the number of objects in your scene...
There's no way around that... it doesn't change the fact that the best way to do the kind of input you want to do is the way you already know.
Your answer
Follow this Question
Related Questions
Add 2d rigidbodies to moving objects to increase performance or not? 1 Answer
Are my kinematic rigidbodies slowing my scene down? 2 Answers
Raycaste vs trigger Colliders & Rigidbody performance 1 Answer
Is it possible to combine child trigger of a object to only trigger OnTriggerEnter once? 1 Answer
Is there any way to make convex meshes with size about 0.1 unit work correct? 0 Answers