PhysicsUserData
Custom user data. The physics system doesn't use this data, it is entirely for custom use.
Read time 1 minuteLast updated 6 days ago
Definition
- Type: Struct
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
- Implements: IEquatable<PhysicsUserData>
public struct PhysicsUserData : IEquatable<PhysicsUserData>
Remarks
To attach a instance to a PhysicsWorld, PhysicsBody, PhysicsShape, PhysicsChain, or PhysicsJoint, assign it to the object's property.
PhysicsUserDatauserDataAdditional Resources: _userData
Examples
// 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; }}
Properties
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 _objectValueId. |
| objectValueId | The EntityId of a Unity object. This is the object referred to with _objectValue |
| physicsMaskValue | A custom 64-bit PhysicsMask. |
| vector3IntValue | A custom Vector3Int. |