Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

PhysicsWorld.Create

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static PhysicsWorld Create();

Returns

PhysicsWorld The created world.

Description

Create a PhysicsWorld using the PhysicsWorldDefinition.defaultDefinition.


Declaration

public static PhysicsWorld Create(PhysicsWorldDefinition definition);

Parameters

Parameter Description
definition The world definition to use when creating the new physics world.

Returns

PhysicsWorld The created world.

Description

Create a PhysicsWorld.

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 true to pause its simulation.

Additional resources: PhysicsWorld.defaultWorld, PhysicsWorldDefinition

 // 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); } }

Declaration

public static PhysicsWorld Create(Snapshot snapshot, PhysicsWorldDefinition definition);

Parameters

Parameter Description
snapshot A snapshot produced by PhysicsWorld.CreateSnapshot.
definition The world definition supplying the settings the snapshot does not store.

Returns

PhysicsWorld The created world restored to the snapshot state, or an invalid world if the snapshot was rejected or no world could be created.

Description

Creates a new PhysicsWorld from snapshot, using definition for the settings a snapshot does not store.

A snapshot restores the full simulation configuration, so these PhysicsWorldDefinition properties are taken from snapshot and their values in definition are ignored: PhysicsWorldDefinition.gravity, PhysicsWorldDefinition.bounceThreshold, PhysicsWorldDefinition.contactHitEventThreshold, PhysicsWorldDefinition.contactFrequency, PhysicsWorldDefinition.contactDamping, PhysicsWorldDefinition.contactSpeed, PhysicsWorldDefinition.contactRecycleDistance, PhysicsWorldDefinition.maximumLinearSpeed, PhysicsWorldDefinition.sleepingAllowed, PhysicsWorldDefinition.continuousAllowed, PhysicsWorldDefinition.eventGroupingAllowed and PhysicsWorldDefinition.capacity. All other definition 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. Creating and restoring a world processes the whole image, so this is not intended to be called at high frequency.