# ReplacePrefab

> Replaces the targetPrefab with a copy of the game object hierarchy go.

## Definition

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

## ReplacePrefab(GameObject, Object)

Replaces the targetPrefab with a copy of the game object hierarchy go.

> **Warning:**
>
> **Deprecated.** Use SaveAsPrefabAsset with a path instead.

```csharp
public static GameObject ReplacePrefab(GameObject go, Object targetPrefab)
```

### Parameters

**** (\[GameObject]\(/engine/6000.0/script-reference/unityengine/gameobject)): **** (\[Object]\(/engine/6000.0/script-reference/unityengine/object)):&#x20;

### Returns

| Type                                                                    | Description |
| ----------------------------------------------------------------------- | ----------- |
| [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) |             |

### Remarks

Returns the Prefab game object after it has been created. If connectToPrefab is enabled go will be made an instance of the created Prefab.

## ReplacePrefab(GameObject, Object, ReplacePrefabOptions)

Replaces the targetPrefab with a copy of the game object hierarchy go.

> **Warning:**
>
> **Deprecated.** Use SaveAsPrefabAsset or SaveAsPrefabAssetAndConnect with a path instead.

```csharp
public static GameObject ReplacePrefab(GameObject go, Object targetPrefab, ReplacePrefabOptions replaceOptions)
```

### Parameters

**** (\[GameObject]\(/engine/6000.0/script-reference/unityengine/gameobject)): **** (\[Object]\(/engine/6000.0/script-reference/unityengine/object)): **** (\[ReplacePrefabOptions]\(/engine/6000.0/script-reference/unityeditor/replaceprefaboptions)):&#x20;

### Returns

| Type                                                                    | Description |
| ----------------------------------------------------------------------- | ----------- |
| [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) |             |

### Remarks

Returns the Prefab game object after it has been created. If connectToPrefab is enabled go will be made an instance of the created Prefab.
