Search Unity

GetRootGameObjects is creating mysterious hidden gameobjces, or so it thinks..

Discussion in 'Editor & General Support' started by CloudyVR, Oct 13, 2017.

  1. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    715
    Hi,

    I am very confused by the operation of GetRootGameObjects.

    in my script I have:
    Code (csharp):
    1. var rootObjs = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects()
    Whenever I make a change to the script and save it I notice that the length of the rootObjs array gets larger by one every time. But I do not see any new root objects added to the hierarchy.

    Also I have 31 root objects in my hierarchy, but the length of rootObjs is now up to 117 and climbing.

    Why is it acting so unexpectedly. And why is it apparently adding non existent gameobjects to the list every time I modify and save the script?

    So weird...

    [Update]

    Just restarted Unity and the count went back to 31, so I modified the script and saved and it now says 32.

    [Update]

    Heres is a post with the full code example that generates this issue.
     
    Last edited: Oct 13, 2017