# World.ActiveWorldScope

> Makes a World the World.DefaultGameObjectInjectionWorld for the lifetime of the scope, and restores the previous one when the scope ends - including when the body throws.

## Definition

* **Type:** Struct
* **Namespace:** [Unity.Entities](/engine/7000.0/script-reference/unity/entities.md)
* **Assembly:** UnityEngine.EntitiesModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public readonly struct World.ActiveWorldScope : IDisposable
```

## Remarks

Use this wherever the borrow fits a single scope. Where it cannot - a borrow spanning a test's setup and teardown, for example - call [World.PushWorldStack](/engine/7000.0/script-reference/unity/entities/world/pushworldstack.md) and [World.PopWorldStack](/engine/7000.0/script-reference/unity/entities/world/popworldstack.md) directly instead.

Scopes must end in the reverse of the order they began; [World.ActiveWorldScope.Dispose](/engine/7000.0/script-reference/unity/entities/world/activeworldscope/dispose.md) throws otherwise.

## Examples

```csharp
using (new World.ActiveWorldScope(myWorld))
{
    // World.DefaultGameObjectInjectionWorld is myWorld here.
}
```

## Constructors

| Constructor                                                                                                             | Description                                           |
| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| [ActiveWorldScope(Unity.Entities.World)](/engine/7000.0/script-reference/unity/entities/world/activeworldscope/ctor.md) | Pushes `world` onto the currently active World stack. |

## Methods

| Method                                                                                      | Description                                                                                                                       |
| ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| [Dispose](/engine/7000.0/script-reference/unity/entities/world/activeworldscope/dispose.md) | Pops the [World](/engine/7000.0/script-reference/unity/entities/world.md) this scope pushed, restoring the previously active one. |
