# LoadPrefabContents(string)

> Loads a Prefab Asset at a given path into an isolated Scene and returns the root GameObject of the Prefab.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static GameObject LoadPrefabContents(string assetPath)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path of the Prefab Asset to load the contents of.

### Returns

| Type                                                                    | Description                      |
| ----------------------------------------------------------------------- | -------------------------------- |
| [GameObject](/engine/6000.6/script-reference/unityengine/gameobject.md) | The root of the loaded contents. |

### Remarks

You can use this to get the content of the Prefab and modify it directly instead of going through an instance of the Prefab. This is useful for batch operations.

To release the prefab and isolated scene from memory when you are finished with it, call [PrefabUtility.UnloadPrefabContents](/engine/6000.6/script-reference/unityeditor/prefabutility/unloadprefabcontents.md). If you modified the Prefab contents, use [PrefabUtility.SaveAsPrefabAsset](/engine/6000.6/script-reference/unityeditor/prefabutility/saveasprefabasset.md) to save any changes, and then call [PrefabUtility.UnloadPrefabContents](/engine/6000.6/script-reference/unityeditor/prefabutility/unloadprefabcontents.md).

Additional Resources: [PrefabUtility.EditPrefabContentsScope](/engine/6000.6/script-reference/unityeditor/prefabutility/editprefabcontentsscope.md).

### Examples

```csharp
using UnityEngine;
using UnityEditor;

public class Example
{
    [MenuItem("Examples/Add BoxCollider to Prefab Asset")]
    static void AddBoxColliderToPrefab()
    {
        // Get the Prefab Asset root GameObject and its asset path.
        GameObject assetRoot = Selection.activeObject as GameObject;
        string assetPath = AssetDatabase.GetAssetPath(assetRoot);

        // Load the contents of the Prefab Asset.
        GameObject contentsRoot = PrefabUtility.LoadPrefabContents(assetPath);

        // Modify Prefab contents.
        contentsRoot.AddComponent<BoxCollider>();

        // Save contents back to Prefab Asset and unload contents.
        PrefabUtility.SaveAsPrefabAsset(contentsRoot, assetPath);
        PrefabUtility.UnloadPrefabContents(contentsRoot);
    }

    [MenuItem("Examples/Add BoxCollider to Prefab Asset", true)]
    static bool ValidateAddBoxColliderToPrefab()
    {
        GameObject go = Selection.activeObject as GameObject;
        if (go == null)
            return false;

        return PrefabUtility.IsPartOfPrefabAsset(go);
    }
}
```
