- Home /
Differenciate in-scene object from loaded object when using Resources.FindObjectsOfTypeAll
Hey,
I'm getting lists of objects by using Resources.FindObjectsOfTypeAll, and I'd like to differentiate those that are instantiated in the current scene from those which are merely "loaded". In the editor, I do that by checking the PrefabType of the object (EditorUtility.GetPrefabType; if Prefab or ModelPrefab then it's an asset, not a scene object), however this is editor only. Any idea how to do that at runtime?
Note: I need to use Resources.FindObjectsOfTypeAll because this will return inactive gameObjects, which is what I want.
Thanks,
Ben
Answer by Kourosh · Apr 20, 2011 at 05:08 PM
Simple and fast solution would be to attach a script to your prefabs with a public boolean variable. Then in the Start function of this script set the boolean value to true. So when you store your objects of the type you can check the boolean variable of each and store those with true value in a separate array.
Thanks $$anonymous$$ourosh. That's akin to checking the active flag of the GameObject I guess. As I said, I need to account for inactive objects, and Start will not be called on these. So to rephrase my question: how do I differenciate between an inactive GameObject in the scene and a loaded - but not instantiated - GameObject?
Ok now got it. Have you tried the tagging system. Here is what I would do: I would define 2 tags (1. inactive 2.notInstantiated) then I would assign my objects one of these tags accordingl. Since "FindObjectsOfTypeAll" will return all objects then you can simply check each returned object's tag in a loop and store them separately or do whatever should be done.
Interesting, but then I'd lose the ability to use the tag for other purposes. I'll keep that as a backup idea in case nothing else comes up. Thanks :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613124040im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scripts still operate even when not active... 1 Answer
How to replace the old "Awake"? 1 Answer
SetActiveRecursively Question 1 Answer
Access Script from inactive game object 0 Answers
FindObjectsOfType doesn't find instantiated objects 0 Answers