Version: 2017.3

PrefabUtility.FindRootGameObjectWithSameParentPrefab

Switch to Manual
public static GameObject FindRootGameObjectWithSameParentPrefab (GameObject target);

Parameters

destinationScene Scene to instantiate the prefab in.

Returns

GameObject The GameObject at the root of the prefab.

Description

Returns the topmost game object that has the same prefab parent as target.

A prefab internally consists of a Prefab object and the list of objects used for the prefab. The Prefab object has a pointer to the root game object and if the prefab is an instance then it also contains a pointer to the asset it was created from and a list of modifications done to the instance.

This only returns a valid result when a prefab instance object, or an object that has been disconnected from a prefab, is used.

The function finds the transform associated with the input object. It will the walk up the ancestors of the transform tree as long as the transform was instantiated from the same prefab asset. Once it reaches the transform that matches the transform on the root game object of the prefab asset it will stop and returns the game object instance.

This is similar to PrefabUtility.FindPrefabRoot but it also works if the prefab instance has been disconnected. This is useful if you have a disconnected prefab instance object and you want to reconnect it to the prefab asset.

This returns a valid result when a prefab instance object, or an object that has been disconnected from a prefab, is used. This function finds the transform associated with the input object. It will the walk up the ancestors of the transform tree as long as the transform was instantiated from the same prefab asset. Once it reaches the transform that matches the transform on the root game object of the prefab asset it will stop and returns the game object instance. This is similar to FindPrefabRoot but it also works if the prefab instance has been disconnected. This is useful if you have a disconnected prefab instance object and you want to reconnect it to the prefab asset.