Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

public struct PhysicsUserData : IEquatable<PhysicsUserData>

Remarks

To attach a
PhysicsUserData
instance to a PhysicsWorld, PhysicsBody, PhysicsShape, PhysicsChain, or PhysicsJoint, assign it to the object's
userData
property.
Additional 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

boolValueA custom bool.
floatValueA custom 32-bit float.
int64ValueA custom 64-bit long.
intValueA custom 32-bit int.
objectValueA custom Unity object. To get the EntityId of the object, use _objectValueId.
objectValueIdThe EntityId of a Unity object. This is the object referred to with _objectValue
physicsMaskValueA custom 64-bit PhysicsMask.
vector3IntValueA custom Vector3Int.