Search Unity

Finding the differences between two game objects and their children

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dark-Protocol, Feb 24, 2017.

  1. Dark-Protocol

    Dark-Protocol

    Joined:
    Nov 19, 2011
    Posts:
    279
    I'm creating a simple nested prefab system for my project and I stumbled upon a problem which I'm not sure how to solve so I hope that someone else would be able to shed some light on the issue.

    You know how when you drag a prefab in the scene, you can put newly created objects in its hierarchy and the prefab connection isn't lost, right? So for example I can drag a prefab in the scene, select it and click GameObject->Create Empty Child and this will still preserve the prefab connection. Not only that but I can also change the order of objects inside the instantiated prefab and this will still preserve the connection as long as I don't modify the hierarchy.

    Another thing is that I can rename all of the objects of the instantiated prefab without breaking the connection so I can't rely on object names either when finding differences.

    Now my question is how can I find the differences between a prefab instance with added children and a fresh prefab instance? What is the best way to determine which objects are "foreign" to the prefab?

    Ideally I would be able to get a list of all native prefab children and another list of all foreign objects upon creating the instance.