# Create a world with the Physics Core 2D API

> Create a new world to add 2D physics objects to, or fetch the default world Unity automatically creates.

> **Note:**
>
> This documentation is about writing C# scripts using the `Unity.U2D.Physics` API. To use 2D physics in the Unity Editor using components like the Rigidbody 2D component, refer to [2D physics](/engine/6000.6/manual/unity2d/2d-physics.md.md) instead.

To create physics objects using the Physics Core 2D API, you first need to create a physics world.

## Prerequisites

Before you create a physics world, follow these steps:

1. Create a [MonoBehaviour script file](/engine/6000.6/manual/scripting/fundamental-unity-types/class-mono-behaviour.md): from the main menu, select **Assets** > **Create** > **C# Script**.
2. To import the `Unity.U2D.Physics` API namespace, add `using Unity.U2D.Physics;` at the top of the script.

> **Note:**
>
> You can use the API in any C# script, not only MonoBehaviour script files. But if you use a MonoBehaviour script file, you can configure physics properties in the Editor window of a GameObject, move GameObjects, and attach sprites.

## Fetch the default world

Unity automatically creates a default world. To fetch it, follow these steps:

1. Get the `defaultWorld` property from the `PhysicsWorld` class.

   ```csharp
   PhysicsWorld world = PhysicsWorld.defaultWorld;
   ```

2. Attach the script to a GameObject in your scene.

3. Enter Play mode to run the script.

To adjust the properties of the world, refer to [Configure global Physics Core 2D API settings](/engine/6000.6/manual/unity2d/2d-physics-api/properties/class-physics-core-settings2d.md).

Unity creates or recreates the default world at the following times:

* When the Editor starts.
* When you enter or exit Play mode.
* When your built application starts.

## Create your own world

To create your own world, follow these steps:

1. Create a public `PhysicsWorldDefinition` object that holds the world properties and displays them in the **Inspector** window. For example:

   ```csharp
   public PhysicsWorldDefinition worldDefinition = new PhysicsWorldDefinition();
   ```

   A new definition has a set of default values. For example, gravity is set to -9.81f. For more information about definitions and changing the default values, refer to [Configure objects using definitions](/engine/6000.6/manual/unity2d/2d-physics-api/properties/definitions.md).

   You can also use `PhysicsWorld.defaultDefinition` to get a definition object with the default values.

2. Create a `PhysicsWorld` object with the definition. For example:

   ```csharp
   PhysicsWorld world = PhysicsWorld.Create(worldDefinition);
   ```

3. Attach the script to a GameObject in your scene.

4. To adjust the properties of the world, modify the values in the **Inspector** window.

   To configure the world in your script instead, set the properties of the definition object before you create the world. For more information, refer to [Configure objects using definitions](/engine/6000.6/manual/unity2d/2d-physics-api/properties/definitions.md).

5. Enter Play mode to run the script and create the world.

## Pause a world

A world starts running as soon as you create it. To pause the simulation, set the [`paused`](/engine/6000.6/script-reference/unity/u2d/physics/physicsworld/paused.md) property of the world object to `true`.

## Example

The following example fetches the default world and logs the gravity value to the **Console** window.

```csharp
using UnityEngine;
using Unity.U2D.Physics;

public class GetDefaultWorld : MonoBehaviour
{
    void Awake()
    {
        // Fetch the default physics world
        PhysicsWorld world = PhysicsWorld.defaultWorld;

        // Log the gravity value to check the world is created
        Debug.Log("The gravity in this world is " + world.gravity);
    }    
}
```

## Additional resources

* [Create a physics object](/engine/6000.6/manual/unity2d/2d-physics-api/create-objects/physics-object.md)
* [Configure global Physics Core 2D API settings](/engine/6000.6/manual/unity2d/2d-physics-api/properties/class-physics-core-settings2d.md)
* [PhysicsCore2D repository](https://github.com/Unity-Technologies/PhysicsExamples2D/tree/master) on GitHub
* [World definition reference for the Physics Core 2D API](/engine/6000.6/manual/unity2d/2d-physics-api/reference/world.md)
