Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ApplyMassFromShapes()

Typically a body will automatically calculate the PhysicsBody.MassConfiguration using all the attached shapes. The PhysicsBody.MassConfiguration is automatically updated whenever a PhysicsShape is added, removed or modified. When adding many shapes to a body, you can choose to stop this automatic calculation, therefore improving performance, by disabling _startMassUpdate for each shape being added to the body. This call will result in the PhysicsBody.MassConfiguration being calculated using the currently added PhysicsShape so is typically called after many shapes are added if they have _startMassUpdate disabled. Alternately, if you wish to assign your own PhysicsBody.MassConfiguration then disabling the automatic calculation also makes sense. In either case, you must call this method or set _massConfiguration before any simulation step occurs otherwise the PhysicsBody will exhibit unstable collision behaviour. The PhysicsBody.MassConfiguration will be overwritten when calling PhysicsBody.ApplyMassFromShapes, if _massConfiguration is set or when adding, removing or changing PhysicsShape with _startMassUpdate enabled. Values overridden with _massOverride keep their authored values through this call; it refreshes the values that are computed from the attached shapes.
Read time 2 minutesLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: Unity.U2D.Physics
  • Assembly: UnityEngine.PhysicsCore2DModule
public void ApplyMassFromShapes()