Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetOutermostPrefabInstanceRoot(Object)

Retrieves the GameObject that is the root of the outermost Prefab instance the object is part of.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor
public static GameObject GetOutermostPrefabInstanceRoot(Object componentOrGameObject)

Parameters

componentOrGameObject

The object to check. Must be a component or GameObject.

Returns

Type

Description

GameObjectThe outermost Prefab instance root.

Remarks

The method will search up the parents in the Transform hierarchy until it finds the root of a Prefab instance which is not an applied nested Prefab inside another Prefab.
If the method finds a Prefab instance root which is an added GameObject to another Prefab instance, it will return that root, since it it not an applied nested Prefab root.
The method will return null if the given object is not part of a Prefab instance. This includes GameObjects or components that have been added and not applied to a Prefab instance.
PrefabInstanceRoots (GetOutermostPrefabInstanceRoot(Object))
Overview of which objects are Prefab instance roots.
In the editor, outermost Prefab instance roots have the Overrides dropdown, whereas other Prefab instance roots don’t.