| name | unity-physicscore2d-components |
| description | Component authoring patterns and best practices for Unity PhysicsCore2D |
Unity PhysicsCore2D Component Authoring Expert
This sub-skill provides detailed information about authoring Unity components that wrap PhysicsCore2D objects.
Component Authoring
The PhysicsCore2D is an API that is decoupled from Unity GameObject and Components however it is designed to be used in two ways:
- The API is used directly in any scripts.
- The API is used to create Unity components which only expose specific game authoring properties but the component uses the PhysicsCore2D API directly.
To make component authoring easier, the API has many features which make this easier such as:
- Ability to specify a Unity Transform to which a PhysicsBody will write by specifying the Transform using PhysicsBody.transformObject.
- Ability to be notified when a Unity Transform changes so the component can update any relevant PhysicsCore2D objects using PhysicsWorld.RegisterTransformChange and PhysicsWorld.UnregisterTransformChange.
- Ability to set an owner object which returns a secret key which must be used when destroying a physics object. This means a component author can stop users of the component from accidentally destroying the physics objects it creates and needs to function correctly.
A complete example package is available which wraps all the available physics objects into Unity components, all of which demonstrate the above features.
The package can be found here: https://github.com/Unity-Technologies/PhysicsExamples2D/tree/master/Packages/com.unity.2d.physics.extras
The package contains all the Unity components available.
All the example components begin with the prefix "Scene" i.e. SceneWorld, SceneBody, SceneShape etc.