Custom user data. The physics system doesn't use this data, it is entirely for custom use.
To attach a PhysicsUserData instance to a PhysicsWorld, PhysicsBody, PhysicsShape, PhysicsChain, or PhysicsJoint, assign it to the object's userData property.
Additional resources: PhysicsShape.userData
// Create custom user data and attach it to a shape. using UnityEngine; using Unity.U2D.Physics;
public class PhysicsUserDataExample : MonoBehaviour { void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; PhysicsBody body = world.CreateBody(); PhysicsShape myShape = body.CreateShape(new CircleGeometry { radius = 1.5f });
PhysicsUserData physicsUserData = new PhysicsUserData { objectValue = this, boolValue = true, floatValue = 123.4f, intValue = 567, physicsMaskValue = PhysicsMask.All };
myShape.userData = physicsUserData; } }
| Property | Description |
|---|---|
| boolValue | A custom bool. |
| floatValue | A custom 32-bit float. |
| int64Value | A custom 64-bit long. |
| intValue | A custom 32-bit int. |
| objectValue | A custom Unity object. To get the EntityId of the object, use PhysicsUserData.objectValueId. |
| objectValueId | The EntityId of a Unity object. This is the object referred to with PhysicsUserData.objectValue |
| physicsMaskValue | A custom 64-bit PhysicsMask. |
| vector3IntValue | A custom Vector3Int. |