Legacy Documentation: Version 2018.2 (Go to current version)
LanguageEnglish
  • C#

PrefabUtility.FindRootGameObjectWithSameParentPrefab

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

public static GameObject FindRootGameObjectWithSameParentPrefab(GameObject target);

Parameters

destinationSceneScene 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.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答