- Home /
Rigidbody mass not updating in inspector after calling SetDensity
So, I have a prefab with a Rigidbody and a C# script attached. The prefab has a cube child object with a collider on it. The prefab is instantiated at runtime when the user clicks and the user can change the scale of the object. I call SetDensity on the Rigidbody whenever the volume gets changed in this way but the mass value in the inspector doesn't seem to change from it's initial value that was set in the prefab. If I print out the value of rigidbody.mass just after I call SetDensity it all looks fine - the value is different as it should be but it just doesn't change in the inspector.
It doesn't actually matter as long as the physics engine is recognising that the mass has changed but it does seem weird.. anyone else run into this?
Thanks :D
Answer by JackStix · Nov 29, 2014 at 06:25 PM
I came across this, too. It actually DOES change in-game, but the inspector doesn't show it. Add:
print(rigidbody.mass);
rigidbody.mass = rigidbody.mass;
The first line shows that the change was made; it will be different than in the inspector. The second line will change the value shown in the inspector, but I plan on removing that for release.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Can not change some values in the inspector 1 Answer
How to give dynamically add mass to a gameobject from volume(collider.bounds.size) and density 1 Answer
Distribute terrain in zones 3 Answers
Can I control mass density of colliders in a rigidbody independent of their size? 1 Answer