Search Unity

Cannot change mass in Rigidbody2D [v4.3]

Discussion in 'Scripting' started by Bankler, Nov 14, 2013.

  1. Bankler

    Bankler

    Joined:
    Apr 10, 2012
    Posts:
    66
    After the 4.3 update, this does not work:
    Code (csharp):
    1.  
    2.     void Start () {
    3.         rigidbody2D.mass = 5f;
    4.     }
    5.  
    The mass still 1.0f after this line, in the debugger as well as in the inspector (and the apparent behaviour of the rigidbody). No warning messages or anything. It just doesn't change. Intended?
     
  2. All_American

    All_American

    Joined:
    Oct 14, 2011
    Posts:
    1,528
    Don't you need to do this-

    Code (csharp):
    1.  
    2. gameObject.Ridgidbody2d.mass =  .5f;
     
  3. Bankler

    Bankler

    Joined:
    Apr 10, 2012
    Posts:
    66
    From what I know, rigidbody2D and gameObject.rigidbody2D are references to the same thing. So no, unfortunately that is not the problem (I tried it to be sure btw). Weird thing is that this has worked through the whole alpha and beta, but now suddenly it does not.
     
  4. justin35f

    justin35f

    Joined:
    Jan 19, 2013
    Posts:
    37
    I've run into the same issue. I'm logging the value in the console even, just in case it was some Editor glitch and not displaying. Unfortunately I can't seem to alter the value no matter what I do, other than manually setting it in the editor. This is a big issue for a game I'm making, as the mass needs to be dynamically altered in script. Hopefully this is just a minor bug and it gets fixed in the next patch.
     
  5. progx73

    progx73

    Joined:
    Jan 15, 2014
    Posts:
    1
    Dynamically that don't work, but i've found a little trick, just set gravity off, change your mass and set gravity on,it works in the update function :)

    m1.rigidbody.useGravity = false;
    m1.rigidbody.mass = 9.2f;
    m1.rigidbody.useGravity = true;