Parent everything to gameobject

Hey,

I want everything that is created in the hierarchy to be automatically parented to a gameobject, is this possible without continuously checking every gameobject’s parent/root in the scene?

Solved it by using EditorApplication.hierarchyWindowChanged to check only once if something has changed in the hierarchy

[InitializeOnLoad]
class HierarchyClass
{
    static HierarchyClass()
    {
        EditorApplication.hierarchyWindowChanged += HierarchyChangedCallback;
    }

    static void HierarchyChangedCallback()
    {
        //Do something once, when the hierarchy has changed
    }

If you are instantiating prefabs at runtime: When it is being instantiated use something like

newInstance.transform.SetParent(parentTransform);

or

newInstance = (GameObject)Instantiate(prefab.gameObject, parentTransform);

If you are in the editor, just right click the parent in the hierarchy when creating new objects. (don’t use the GameObject menu in the ribbon)