ApplySnapshot
Restore this world to the state captured in snapshot, in place. The world keeps the same handles, so any PhysicsBody, PhysicsShape and PhysicsJoint you already hold remain valid. Applying a snapshot taken from a different world means existing handles for this world may alias objects restored from the snapshot or report invalid. The snapshot image is fully validated before the world is touched, so a rejected snapshot leaves the world unchanged. A restore changes and destroys objects without their owner keys. It is refused when this world is owned, or when any of its bodies, shapes, chains or joints is owned. The default world is permanently owned by Unity, so a snapshot can be applied to it as long as none of its objects are owned.
Read time 3 minutesLast updated 6 hours ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
ApplySnapshot(Snapshot)
Restore this world to the state captured in , in place. The world keeps the same handles, so any PhysicsBody, PhysicsShape and PhysicsJoint you already hold remain valid. Applying a snapshot taken from a different world means existing handles for this world may alias objects restored from the snapshot or report invalid. The snapshot image is fully validated before the world is touched, so a rejected snapshot leaves the world unchanged. A restore changes and destroys objects without their owner keys. It is refused when this world is owned, or when any of its bodies, shapes, chains or joints is owned. The default world is permanently owned by Unity, so a snapshot can be applied to it as long as none of its objects are owned.
snapshotpublic bool ApplySnapshot(PhysicsWorld.Snapshot snapshot)
Parameters
A snapshot produced by PhysicsWorld.CreateSnapshot on a compatible world.
Returns
Type | Description |
|---|---|
| bool | Whether the world was restored. Returns false if the snapshot or world is invalid, the world or any of its objects is owned, or the image is rejected, in which case the world is unchanged. |
Remarks
A world containing objects created by physics components can't be restored over itself, because those objects are owned. Copy it into a new world instead, with PhysicsWorld.Create or PhysicsWorld.Clone. See PhysicsWorld.Snapshot for what a restore brings back. Use PhysicsWorld.ApplySnapshot to destroy the objects that were owned when the snapshot was created. Validating and applying a snapshot processes the whole image, so this is not intended to be called at high frequency.
ApplySnapshot(Snapshot, bool)
Restore this world to the state captured in , in place, optionally destroying the objects that were owned when the snapshot was created. With set, each owned body is destroyed along with its attached shapes, chains and joints, whether or not they were owned. An owned shape on a body that was not owned is destroyed and the body is kept.
snapshotremoveOwnedpublic bool ApplySnapshot(PhysicsWorld.Snapshot snapshot, bool removeOwned)
Parameters
A snapshot produced by PhysicsWorld.CreateSnapshot on a compatible world.
Whether to destroy the objects that were owned when the snapshot was created, instead of keeping them as unowned objects.
Returns
Type | Description |
|---|---|
| bool | Whether the world was restored. Returns false if the snapshot or world is invalid, the world or any of its objects is owned, or the image is rejected, in which case the world is unchanged. |
Remarks
The restore is refused in the same cases as PhysicsWorld.ApplySnapshot, which this matches when is false. See PhysicsWorld.Snapshot for what a restore brings back. Validating and applying a snapshot processes the whole image, so this is not intended to be called at high frequency.
removeOwned