Create
Create a PhysicsWorld using the _defaultDefinition.
Read time 2 minutesLast updated 11 days ago
Definition
- Type: Method
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
Create()
Create a PhysicsWorld using the _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 _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 _paused to to pause its simulation.
trueAdditional Resources: _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: _gravity, _bounceThreshold, _contactHitEventThreshold, _contactFrequency, _contactDamping, _contactSpeed, _contactRecycleDistance, _maximumLinearSpeed, _sleepingAllowed, _continuousAllowed, _eventGroupingAllowed and _capacity. All other properties are applied normally, for example _simulationWorkers and _simulationSubSteps. To use a value other than the snapshot's, set the matching property on the returned world after this call. Creating and restoring a world processes the whole image, so this is not intended to be called at high frequency.
snapshotdefinitiondefinition