Search Unity

How to get the overrides child of GameObject in script

Discussion in 'Prefabs' started by thong341998, Dec 13, 2019.

  1. thong341998

    thong341998

    Joined:
    Dec 1, 2018
    Posts:
    6
    Hello.
    Im currently working on a tool that when I'm saving a Prefab Instance in scene as PrefabAsset into the asset folder, it will look into that prefab instance and check the child if they had any changes and then automatically saving them into prefab assets.
    The problem is I want to get the list of this overrides child like this image. In this image i want to get cell_0 GameObject, which is the override child.
    Screen Shot 2019-12-13 at 09.43.02.png
    How I do that from script. Thank you
     
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    I don't understand your question exactly, and I can't see from the image what's special about Cell_0 specifically. But you'll find the APIs to get objects with various types of overrides in the PrefabUtility class:
    https://docs.unity3d.com/ScriptReference/PrefabUtility.GetAddedGameObjects.html
    https://docs.unity3d.com/ScriptReference/PrefabUtility.GetAddedComponents.html
    https://docs.unity3d.com/ScriptReference/PrefabUtility.GetRemovedComponents.html
    https://docs.unity3d.com/ScriptReference/PrefabUtility.GetObjectOverrides.html
     
  3. payalzariya07

    payalzariya07

    Joined:
    Oct 5, 2018
    Posts:
    85
    you find a child object, then used this method.

    public void GetChildObject(Transform parent, string _tag)
    {
    for (int i = 0; i < parent.childCount; i++)
    {
    Transform child = parent.GetChild(i);
    if (child.tag == _tag)
    {
    yourlist.Add(child.gameObject);
    }
    if (child.childCount > 0)
    {
    GetChildObject(child, _tag);
    }
    }
    }