Clone
Creates a new PhysicsWorld that is a copy of this world, including all of its PhysicsBody, PhysicsShape and PhysicsJoint.
Read time 2 minutesLast updated 2 days ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
Clone()
Creates a new PhysicsWorld that is a copy of this world, including all of its PhysicsBody, PhysicsShape and PhysicsJoint.
public PhysicsWorld Clone()
Returns
Type | Description |
|---|---|
| PhysicsWorld | The cloned world. |
Remarks
The clone is a separate world, so handles you hold for this world do not resolve against it; enumerate the clone with PhysicsWorld.GetBodies and similar. The clone is not owned and its PhysicsWorld.userData is not copied; callback options come across but any callback targets must be set on the clone. Nothing in the clone is owned, but each object keeps its owner as information. No body has a transform object, so the clone never writes to the Transforms this world drives.
Clone(bool)
Creates a new PhysicsWorld that is a copy of this world, optionally leaving out the objects that are owned. With set, each owned body is left out along with its attached shapes, chains and joints, whether or not they were owned. An owned shape on a body that is not owned is left out and the body is kept.
removeOwnedpublic PhysicsWorld Clone(bool removeOwned)
Parameters
Whether to leave out the objects that are owned, instead of copying them as unowned objects.
Returns
Type | Description |
|---|---|
| PhysicsWorld | The cloned world. |
Remarks
Use this to copy a world built by physics components into a separate world without the objects those components own. The clone is a separate world, so handles you hold for this world do not resolve against it; enumerate the clone with PhysicsWorld.GetBodies and similar. The clone is not owned and its PhysicsWorld.userData is not copied; callback options come across but any callback targets must be set on the clone. Nothing in the clone is owned, but each object keeps its owner as information. No body has a transform object, so the clone never writes to the Transforms this world drives.