Check if prefab is in scene view

Updated on February 3, 2016 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on February 3, 2016

Hi everyone,

how can i check if a prefab is actually in my scene view? My prefab has tag “Enemies” and I am currently using the following line of code to do that:

GameObject.FindWithTag("Enemies").activeInHierarchy == false

However, I was told by some of you that this is not efficient if inside an Update method. Moreover, it always returns “NullReferenceException: Object reference not set to an instance of an object”.

Thx in advance

  • Liked by
0 on February 3, 2016

If you need to find the object during a specific time or after a spwxific event in your game you can make a new method and call it at that time.

  • Liked by