# UnpackAllInstancesOfPrefab(GameObject, PrefabUnpackMode, InteractionMode)

> Unpacks all instances of a given Prefab Asset root GameObject in all open scenes so that all instances are replaced with the contents of the Prefab Asset while retaining all override values.

## Definition

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

```csharp
public static void UnpackAllInstancesOfPrefab(GameObject prefabRoot, PrefabUnpackMode unpackMode, InteractionMode action)
```

### Parameters

**** (\[GameObject]\(/engine/6000.5/script-reference/unityengine/gameobject)): The root GameObject of a Prefab Asset used to find all Prefab instances in open scenes that should be unpacked.**** (\[PrefabUnpackMode]\(/engine/6000.5/script-reference/unityeditor/prefabunpackmode)): Whether to unpack the outermost root or unpack completely.**** (\[InteractionMode]\(/engine/6000.5/script-reference/unityeditor/interactionmode)): The interaction mode to use for this action.

### Remarks

The Prefab instances will not be unpacked in closed scenes. This function uses [PrefabUtility.FindAllInstancesOfPrefab](/engine/6000.5/script-reference/unityeditor/prefabutility/findallinstancesofprefab.md) to determine which instances to unpack and calls [PrefabUtility.UnpackPrefabInstance](/engine/6000.5/script-reference/unityeditor/prefabutility/unpackprefabinstance.md) for each instance.

Unpacking throws an ArgumentException if the given object is not the root GameObject of a Prefab Asset.

### Examples

```csharp
using UnityEditor;
using UnityEngine;

public class Example
{
    public static void UnpackAllInstancesOfPrefab(string prefabPath)
    {
        var prefabAssetRoot = AssetDatabase.LoadMainAssetAtPath(prefabPath) as GameObject;
        if (prefabAssetRoot != null)
        {
            PrefabUtility.UnpackAllInstancesOfPrefab(prefabAssetRoot, PrefabUnpackMode.OutermostRoot, InteractionMode.UserAction);
        }
    }
}
```
