Search Unity

Does a moving camera need a rigidbody attached?

Discussion in 'Scripting' started by Thomas12, Sep 17, 2015.

  1. Thomas12

    Thomas12

    Joined:
    Dec 24, 2014
    Posts:
    36
    Hello,

    quick question : I understand that objects without a rigidbody attached are expected to be static by Unity. Moving such object will result in Unity having to recheck all the static geometry, something we want to avoid.

    The camera in a scene is nothing more than a game object with a camera component attached to it. If my camera is going to move, does it mean I need to add a (possibly kinematic) rigidbody to it to avoid having all the static geometry being recalculated every time this camera moves?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    colliders, not objects

    camera doesn't usually have a collider attached.
     
  3. Thomas12

    Thomas12

    Joined:
    Dec 24, 2014
    Posts:
    36
    What if I have a cube without a collider and I make it move? Does it matter at all that I add a rigidbody component?
     
    Last edited: Sep 17, 2015
  4. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    http://docs.unity3d.com/Manual/CollidersOverview.html
    whether or not a collider is static is based on a check box in the inspector, i.e. your choice, if you set a collider to static the game engine will make optimisations based on that.

    If you then move a collider set to static, it needs to undo or fill in the gaps that those optimisations made, meaning overhead and relatively poor performance.


    You can just not set a collider to static, it won't have the optimisations done to it, it can move happily by whatever method (rigidbody, direct position change through code, whatever).


    Rigidbody is needed if you want to gameobject to be a part of the physics simulation, it doesn't have any affect on the above.
     
  5. flaminghairball

    flaminghairball

    Joined:
    Jun 12, 2008
    Posts:
    868
    Not quite - in the case of colliders, they ARE considered to be static geometry by the physics engine if they do not have a rigidbody attached (the "Static" checkbox does not pertain to this).

    If you have a gameobject with a collider attached but no rigidbody, and you move said collider around, it will incur a performance hit.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    This issue was supposed to be fixed in 5.0. But I would benchmark it if you are concerned.