Create
Create a PhysicsWorld using the PhysicsWorldDefinition.defaultDefinition.
Read time 3 minutesLast updated 5 hours ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
Create()
Create a PhysicsWorld using the PhysicsWorldDefinition.defaultDefinition.
public static PhysicsWorld Create()
Returns
Type | Description |
|---|---|
| PhysicsWorld | The created world. |
Create(PhysicsWorldDefinition)
Create a PhysicsWorld.
public static PhysicsWorld Create(PhysicsWorldDefinition definition)
Parameters
The world definition to use when creating the new physics world.
Returns
Type | Description |
|---|---|
| PhysicsWorld | The created world. |
Remarks
You don't need to create a world before you add physics objects, because Unity automatically creates one you can fetch with PhysicsWorld.defaultWorld. This method isn't thread-safe. Call it only from the main thread. A world starts running as soon as you create it. Set PhysicsWorld.paused to to pause its simulation.
trueAdditional Resources: PhysicsWorld.defaultWorld, PhysicsWorldDefinition
Examples
// Create a public world definition so its properties display in the// Inspector window, then create a world from it.using UnityEngine;using Unity.U2D.Physics;public class CreateWorld : MonoBehaviour{ public PhysicsWorldDefinition worldDefinition = new PhysicsWorldDefinition(); public PhysicsWorld world; void Awake() { world = PhysicsWorld.Create(worldDefinition); }}
Create(Snapshot, PhysicsWorldDefinition)
Creates a new PhysicsWorld from , using for the settings a snapshot does not store.
snapshotdefinitionpublic static PhysicsWorld Create(PhysicsWorld.Snapshot snapshot, PhysicsWorldDefinition definition)
Parameters
A snapshot produced by PhysicsWorld.CreateSnapshot.
The world definition supplying the settings the snapshot does not store.
Returns
Type | Description |
|---|---|
| PhysicsWorld | The created world restored to the snapshot state, or an invalid world if the snapshot was rejected or no world could be created. |
Remarks
A snapshot restores the full simulation configuration, so these PhysicsWorldDefinition properties are taken from and their values in are ignored: PhysicsWorldDefinition.gravity, PhysicsWorldDefinition.bounceThreshold, PhysicsWorldDefinition.bounceIterations, PhysicsWorldDefinition.bouncePropagation, PhysicsWorldDefinition.contactHitEventThreshold, PhysicsWorldDefinition.contactFrequency, PhysicsWorldDefinition.contactDamping, PhysicsWorldDefinition.contactSpeed, PhysicsWorldDefinition.contactRecycleDistance, PhysicsWorldDefinition.maximumLinearSpeed, PhysicsWorldDefinition.sleepingAllowed, PhysicsWorldDefinition.continuousAllowed, PhysicsWorldDefinition.eventGroupingAllowed and PhysicsWorldDefinition.capacity. All other properties are applied normally, for example PhysicsWorldDefinition.simulationWorkers and PhysicsWorldDefinition.simulationSubSteps. To use a value other than the snapshot's, set the matching property on the returned world after this call. Nothing in the new world is owned, but each object keeps its owner as information. No body has a transform object, so the new world never writes to the Transforms the source world drives. Use PhysicsWorld.Create to leave out the objects that were owned when the snapshot was created. Creating and restoring a world processes the whole image, so this is not intended to be called at high frequency.
snapshotdefinitiondefinitionCreate(Snapshot, PhysicsWorldDefinition, bool)
Creates a new PhysicsWorld from , optionally leaving out the objects that were owned when the snapshot was created. 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 was not owned is left out and the body is kept.
snapshotremoveOwnedpublic static PhysicsWorld Create(PhysicsWorld.Snapshot snapshot, PhysicsWorldDefinition definition, bool removeOwned)
Parameters
A snapshot produced by PhysicsWorld.CreateSnapshot.
The world definition supplying the settings the snapshot does not store.
Whether to leave out the objects that were owned when the snapshot was created, instead of keeping them as unowned objects.
Returns
Type | Description |
|---|---|
| PhysicsWorld | The created world restored to the snapshot state, or an invalid world if the snapshot was rejected or no world could be created. |
Remarks
Use this to copy a world built by physics components into a separate world without the objects those components own. The settings come from and in the same way as PhysicsWorld.Create. Nothing in the new world is owned, but each object keeps its owner as information. No body has a transform object, so the new world never writes to the Transforms the source world drives. Creating and restoring a world processes the whole image, so this is not intended to be called at high frequency.
snapshotdefinition