- Home /
PhysX and multiple instances at same location
I have a code that is instantiating around 1000 objects at the same location using a coroutine. The problem is that all those objects have a box collider with "isTrigger=true" and a kinematic rigidbody attached to them and because of that they are triggering this error:
"Too many pairs created, new pairs will be ignored. This is perhaps due to an excessive number of objects created at one location."
Also, the game becomes slow while the objects are colliding with each other but as soon as they move and stop colliding with each other, it starts running smoothly.
I tried to setup the Layer-Based Collision Detection of Physics in order to ignore the collision of all these objects between themselves but the error still appears.
So what can I do in order to have multiple instances of those objects at the same location and also check for collisions only with another 2 object layers?
EDIT
I forgot to mention that I need it to work smothly on Android and iOS with a maximum of 500 objects at the same initial location (because after they move out of collision with themselves, they already move smoothly)
EDIT 2
It works fine with +/- 500 objects on editor but on Android it doesn't work well. On editor, if I try to create 1000 objects then I get +/- the same frame rate as in Android.
EDIT 3
As asked, I created a simple example project that shows what's happening. Just open it, hit play and se what happens when the cubes appear and start to move.
Assu$$anonymous$$g you set up your layer collision matrix correctly it should work fine. Are you using 2d or 3d colliders?
Aren't particles too expensive for mobile? Also, my objects start all at the same location but then they end all on different locations.
Answer by Xtro · Mar 12, 2014 at 02:40 PM
Try adding rigidbody to them and set the isKinematic = true.
The colliders without rigidbodies are considered as "static" colliders. If you move them, it reduces performance.
The colliders with rigidbodies are considered as "dynamic" colliders. Moving them doesn't cost as much as it costs for static colliders.
Having too many dynamic colliders may have different side effect but still it's worth a try.
Please let me know about the results.
Already tried that. The only way they run smoothly is when I disable the box collider or If I remove the rigidbody and disable the "isTrigger" but, I can't do any of those solutions because I need to check collisions with other 2 layers (Frag and $$anonymous$$ounter)
Here's a screenshot of the actual configuration of collider and rigidbody for the Split objects:
Is the transform scale of the objects uniform? Like (1,1,1) or (2,2,2) ?
I think it is a known issue that colliders have problems with non uniform transform scales.
I am very interested in the resolution of that kind of physics problems in Unity.
If you can create a very small example project having the same issue and send it to me, I would be happy to investigate it.
It is not uniform. I will try to put it uniform and see what happens.
I can't replicate the project because it's a project from the company where I work and so, I can't add the original assets.
I don't want you to add the assets. It can be very empty project with only having the object spawner script and the trigger objects which are causing the performance loss.
Games are not actual simulations. You can fake some things. Since it's gonna be very fast, no body would notice it. Even if they notice they don't care because this is a game. Just create the items in random positions around the center of the missile.