Legacy Documentation: Version 5.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

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

Sumbission failed

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

Close

Cancel

public static function FindRootGameObjectWithSameParentPrefab(target: GameObject): GameObject;
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.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961