Version: 2017.2

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.

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