For example, when using this function to search for Transforms in the default scene setup that Unity gives you when you make a new scene, it finds internal objects called “SceneLight”, “SceneCamera”, and “” (the object’s name is the empty string).
How can I tell if an object is internal to the engine (like the Scene View Camera)? Clearly, Unity internally has some way of determining this because these objects don’t show up in the results when you search for Transforms with Object.FindObjectsOfType.
I have tried filtering out objects with the HideInHierarchy bit set in their hideFlags, and while this will filter out internal objects, it also filters out user-created objects with that bit set. So I need a way of determining if an object is internal without giving false positives.
The reason I need this is so I can implement a version of Object.FindObjectsOfType that can find inactive objects (still not sure why Unity itself hasn’t done this yet).
A ‘FindObjectsOfType’ method would still return objects of a known type.
I’m going to assume it accepts a ‘type’ parameter, and you’re going to compare to that, so thusly the type passed in will need to be known.
If the object isn’t that type, then don’t return it. It being an internal type is inconsiquential, seeing as that ‘type’ parameter should never actually be an internal type.
Basically these internal types will be excluded algorithmically without you even needing to test for if they are or not. A SceneLight isn’t a Transform, so SceneLight will fail your ‘obj is Transform’ test.
Hmm, I think you may be misunderstanding the scenario that I described in my first post. Let me see if I can explain it a little better:
I call Resources.FindObjectsOfTypeAll because I want to find all Transforms in my scene (including those that may be disabled).
Unfortunately, Unity has some internal GameObjects named “SceneLight”, “SceneCamera”, etc. that each have a Transform component (all GameObjects in the hierarchy have a Transform), so their Transforms show up in the array returned by Resources.FindObjectsOfTypeAll.
If I were to instead call Object.FindObjectsOfType, I would not get the Transforms of “SceneLight”, “SceneCamera”, etc. since that function will not give you internal Unity-owned objects. But that function is not able to find Transforms on inactive GameObjects, which I need in my use case.
How can I distinguish between a Unity internal object and an object that is a normal part of my scene so that I can filter out the Unity internal objects from the array returned by Resources.FindObjectsOfTypeAll()?
It is true that you can use the HideFlags to filter out Unity internal objects, but the problem with this technique is that it can give you false positives since it can also filter out user generated objects with the same HideFlags.
Unfortunately, this is potentially dangerous in my company’s project since we use many 3rd party plugins from the Asset Store (some of which don’t provide source code), so it is entirely possible that some plugins are spawning GameObjects in edit mode that are also HideAndDontSave, thus making them indistinguishable from Unity internal objects by that metric.