# OpenPreviewScene(string)

> Opens a Scene Asset in a preview Scene.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor.SceneManagement](/engine/6000.3/script-reference/unityeditor/scenemanagement.md)
* **Assembly:** UnityEditor

```csharp
public static Scene OpenPreviewScene(string scenePath)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): Scene file to open.

### Returns

| Type                                                                          | Description                |
| ----------------------------------------------------------------------------- | -------------------------- |
| [Scene](/engine/6000.3/script-reference/unityengine/scenemanagement/scene.md) | The created preview Scene. |

### Remarks

You can use this function for tooling that needs to access GameObjects but where the scene should not be displayed in the Hierarchy. Make sure to call [EditorSceneManager.ClosePreviewScene](/engine/6000.3/script-reference/unityeditor/scenemanagement/editorscenemanager/closepreviewscene.md) to prevent leaking scenes.

Additional Resources: [EditorSceneManager.NewPreviewScene](/engine/6000.3/script-reference/unityeditor/scenemanagement/editorscenemanager/newpreviewscene.md), [EditorSceneManager.ClosePreviewScene](/engine/6000.3/script-reference/unityeditor/scenemanagement/editorscenemanager/closepreviewscene.md).

### Examples

```csharp
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;

public static class TestOpenAsPreviewScene
{
    [MenuItem("Assets/Scene Root Names")]
    static void OpenContextClickedSceneInAPreviewScene()
    {
        SceneAsset sceneAsset = Selection.activeObject as SceneAsset;
        if (sceneAsset == null)
        {
            Debug.Log("Context click on a Scene Asset file");
            return;
        }

        var assetPath = AssetDatabase.GetAssetPath(sceneAsset);
        var scene = EditorSceneManager.OpenPreviewScene(assetPath);
        try
        {
            var rootGameObjects = scene.GetRootGameObjects();

            Debug.Log($"Root GameObject Names (count: {rootGameObjects.Length})");
            foreach (var gameObject in rootGameObjects)
                Debug.Log(gameObject.name);
        }
        finally
        {
            EditorSceneManager.ClosePreviewScene(scene);
        }
    }
}
```
