Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Attach custom data to 2D Physics Core objects

Attach values and physics masks to physics objects so you can fetch them later.
Read time 1 minuteLast updated 14 days ago

To attach custom data to a 2D Physics Core component, use the User Data section of the
Inspector

?

window.
Note
This documentation is about using Pose, Area, and Constraint components. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to 2D physics instead.
Follow these steps:
  1. Select a GameObject with any 2D Physics Core component.
  2. In the Inspector window, expand the User Data section.
  3. Set a value for one of the custom properties. For example, set Int to 42 to attach the integer value of 42 to the component.
To fetch the data in the API, get the
userData
property of the physics object. For example:
Debug.Log(myShape.userData.intValue);

Additional resources