Arcana Affinity
Arcana Affinity

Reputation: 307

A collider is better to be static when checking collision?

So... As far as I know it's only good practice to make any GameObject Static if that object is not meant to move, therefore I also thought even a rolling stone with a rigidbody shouldn't be a static GameObject.

However, I was commented by someone as a 'Unity Tip FYI' the physics calculation spikes up when an object checks collision whilst it's rotating, so to make the collider static for the sake of better performance(even meer small amount).

I'm really not getting this idea. Does this make any sense to anyone here??

Upvotes: 1

Views: 4913

Answers (2)

Galandil
Galandil

Reputation: 4249

A static game object is not the same as a static rigidbody/collider, they're two completely different concept.

Static game objects are used to save performance time/memory regarding rendering, navigation meshes, etc., you can read about them here: https://docs.unity3d.com/Manual/StaticObjects.html

Static colliders are a totally different beast. A static collider is used to tell Unity that this object will never move under any circumstance, so it will save quite some calculations in the physics engine.

Finally, regarding the tip that you mentioned: I think that probably the author of that tip was talking about 3D colliders, and by "static" he meant that you should separate the 3D mesh from the 3D collider, so when the mesh must be rotated, you rotate only that and not the collider.

Think of a sphere, you create a parent game object, then two children: one that has the Mesh component, and the other the Sphere collider. When you want to rotate the sphere in place, you only rotate the mesh child and not the collider, and when you want to translate instead the sphere, you just translate the parent game object in order to change the position of both children.

Upvotes: 1

Programmer
Programmer

Reputation: 125455

Not exactly sure what that comment is saying. It doesn't make sense. Also, it looks like you are confusing static collider and marking GameObject as static.

  • Marking Object as static from the Editor

    Telling Unity to batch it. It is used to increase rendering performance. (This has nothing to do with colliders)

  • Static Collider

    Telling Unity that the Rigidbody will not be moved.

From your question, you are describing Static Collider. Static Collider work for both 3D and 2D physics system.

What is a Static Collider:

Static Collider is when you have a GameObject with any type of collider but no Rigidbody attached to it.

How to create a Static Collider: To make a GameObject a Static Collider on, attach a collider to that GameObject but don't attach Rigidbody to it. It is now a Static Collider.

To make it non Static Collider, attach Rigidbody to it.

What it is used for:

When you have many Objects that you want your collide with but you are 100 percent sure that this Object will not be moved by you or player.

One good example is a brick wall. You simply want the wall to stop the player but you don't want to move the wall. It could also be used for stones in an environment to prevent player collison. Imagine having to attach hundreds or thousands of Rigidbodies to each stone Object with a collider.

It is used to increase physics performance.

What happens when you move a Static Collider:

Don't. When GameObject is made to be Static Collider, it is expected that you never move it. If you do, it will spike cause spike in CPU. This introduces constant freezing in your game each time you try to move it. This spike has been reduced in Unity 5 but it is still there. I think that's what that comment is trying to say. This whole thing happens because it has to recalculate the physical world all over again. From Unity's website, below is a screenshot of what happens when you try to move a Static Collider Object.

enter image description here

Upvotes: 1

Related Questions