Version: 2022.3
LanguageEnglish
  • C#
Method group is Obsolete

PrefabUtility.ConnectGameObjectToPrefab

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Obsolete Use ConvertToPrefabInstance() or ReplacePrefabAssetOfPrefabInstance() which has settings for better control.

Declaration

public static GameObject ConnectGameObjectToPrefab(GameObject go, GameObject sourcePrefab);

Parameters

go The disconnected GameObject that you want to reconnect.
sourcePrefab The source Prefab to connect to the GameObject.

Description

Connects the source Prefab to the game object.

This method allows you to reconnect a GameObject to its source Prefab, when it has become disconnected. Prior to 2018.3 it was possible for Prefab instances to become disconnected from their source Prefab. This method fixes that connection. From 2018.3 onwards, Prefabs cannot become disconnected, so this method exists only to correct problems that may exist in projects created in earlier versions of Unity.