Should I make sure a rigidbody is on same GameObject or parent?
I donāt think so⦠anybody?
The question doesnāt make sense really.
A Collider thatās non-static but doesnāt have a Rigidbody means that itās on a child GameObject and is implicitly attaching to a Rigidbody on a parent GameObject. That doesnāt have a cost, nor did it ever.
The only thing that changed in 3D physics is moving a Static Collider i.e. a Collider that doesnāt have a Rigidbody to attach to change to be far less expensive in 5.5.
Is it still slower than moving a non-static collider?
Sorry but your questions are too vague. I am even presuming you mean 3D physics and not 2D physics. How do you āmoveā the collider? Do you set the Transform or using Rigidbody(2D).MovePosition? Why is this even an issue for you? Are you seeing some problem?
If you want to move a collider yourself instead of the physics system doing so and it to not respond to forces then add a Kinematic Rigidbody (IsKinematic=true). If you want the physics system to move it and it to respond to forces then use a Dynamic Rigidbody (IsKinematic=false). If you donāt want the physics system to move it and youāre not moving it and it not to respond to forces then use a Static Rigidbody (for 3D physics you just donāt add a Rigidbody, in 2D you can explicitly set the bodyType).
Itās not an issue, Iām just asking out of curiosity and I only had one question.
The profiler used to issue a warning, if I moved a gameobject (by setting the transform.position directly) that had a collider (Iām talking about 3D physics, which I thought was clear, since I quoted you talking about 3D physics), without a kinematic rigid body.
And since this was a thing that a lot of developers did (by mistake, or simply not knowing better), I believe this case was optimized (at least, thatās what I remember reading on a Unity blogpost, please correct me if Iām wrong).
So to be more specific:
Is doing GameObject.transform.position = new Vector3(a,b,c); (assume a,b,c are random values) faster on a gameobject that has a collider and a rigidbody set to kinematic, or on a gameobject that just has a collider (at which point, I believe the collider is considered to be āstaticā)?
EDIT:
From this blogpost: https://blogs.unity3d.com/2014/07/08/high-performance-physics-in-unity-5/
Which makes me think that moving a static collider and a rigidbody-less collider is now the same thing, which certainly wasnāt the case in Unity 4. Is it? Or are there still differences?
Iām a 2D physics dev not a 3D one so Iām not sure on the exact improvement made. From what I understand, the overhead has been completely removed or the difference is negligible so they should be the same but itās a really easy thing to test with the profiler surely?
I will add finally that I see this kind of thing being asked all the time as if adding a Kinematic Rigidbody is something to be avoided or bad to do if youāre explicitly moving a collider. Itās what it is designed for. I think it stems from the (in my opinion) bad decision early on in Unity to allow not adding a Rigidbody to implicitly mean Static. Note this isnāt some dig at you at all, just my observation that this implicit action raises needless question on what is a good way of doing things because yeah, less is better (not adding a component).
There have been tests, they were kinda inconclusive
(but it seems they are now roughly in the same ballpark in terms of performance)
Iām adding rigidbodies when I intend to move colliders, so itās not an issue for me personally. Itās a bit weird workflow though (which you seem to agree on).
The thing is, on the forums, there was a big push to educate people on this issue, since a lot of people did it wrong (in the Unity 4 era).
Then there was the blog post I posted above, which led people to believe, that for Unity 5, kinematic rigidbody or not, itās the same thing now, at least performance wise.
But then the manual ( https://docs.unity3d.com/Manual/CollidersOverview.html ) says
Which is the opposite. But then again, as a lot of things in the manual, it could just be very outdated.
So you can probably see why people are a bit confused as what the ābest practiceā is.
And to confuse things even further, it seems moving colliders without rigidbodies is actually much faster according to a quick test I just did.
Yeah, so, moving 1000 box colliders takes about 2.8ms, and if I attach a Kinematic Rigidbody on the parent object (or to all cubes individually, it makes no difference it seems), it needs around 27ms.
So maybe Iām doing something wrong, or the manual is flat out wrong, or thereās a bug?
At this point, itās better to speak to a 3D physics dev such as Anthony Yakolev ( @yant ).
Can I have a look at your particular project with 2.8ms / 27ms difference?
In general, one is advised to have a RB on all the physics objects that are moved from scripts as otherwise some parts of the world might not get updated properly (example: a ball sleeping on a static box wonāt always be awaken if you remove the static box; a performance optimisation in the physics engine).
As for your earlier questions, weāve had moving of static objects sped up significantly in Unity 5.0 Unity Blog thatās why the performance warning was removed.
Anthony
I submitted a bug report (as a documentation bug, since I really donāt know if itās an actual bug, or if the docs are simply outdated). I had a repro scene attached with it. Itās case 873057.
From the tests Iāve made, it seems like moving non-rigidbody colliders is now the fastest thing. Itās faster than moving kinematic rigidbody colliders or non-kinematic rigidbody colliders.
This surprised me because it was kind of a well-known Unity thing that everytime you had to move colliders, it was better if they had rigidbodies, but apparently this isnāt true anymore
@yant Any update on this?
Which is fine, btw. Having to add a rigidbody just to mark a collider as ānon-staticā was always kinda weird.
So itās good that it was changed. The thing is we donāt know how exactly it was changed and the manual saying the complete opposite of what is happening isnāt helping.
Iām not sure thereās an actual bug here, the thing needed could be a complete rewrite of that section in the manual.
@AcidArrow What Unity version do youāve used with your test?
Iāve tested it myself with 1000 moving cubes and got the same result (kinematic rigidbodies are slower) @ Unity 5.4.
Hi
Iām moving thousands of trigger colliders every frame ( using their transform )
Iāve had a kinematic rigidbody attached to every trigger, but Iāve tried removing it and the performance changed significantly ( from about 15 fps to 40 fps )
The player ( with a rigidbody ) is still able to collide with the triggers without any issues.
I wanted to know if this might introduce bugs or if some collisions might not be detected ?
@larex39 Thanks, but I think I have the opposite issue
removing the kinematic rigidbodies really enhances performance
Right now iām just concerned of getting weird physics behavior since unity recommends adding rigidbodies to any trigger collider that moves