- Home /
How do I check if a game object exist in hierarchy ?
i want to check if a prefab exist in hierarchy and when it not exist i want to move on to the next level, i want to check if a prefab existing in hierarchy and when it not exist i want to move on to next level
The simplest and naive solution is to use GameObject.FindObjectOfType(). If it's returns a reference then the object exists and everything else is up to you.
@Ildar$$anonymous$$asimov That just finds if there's an object with a particular component attached, which has nothing whatsoever to do with prefabs
That's easy. Prefabs don't exist in the hierarchy :)
If you want to know if a prefab has an instance in the hierarchy, that's potentially quite a complex question, depending on what version of Unity you're using.
Assu$$anonymous$$g that you are asking about an instance of a prefab, and that you're using 2018.3 or later... does it have to be a direct instance or could it be an instance of a variant of your prefab?
Answer by rohitkvasanth · May 20, 2019 at 06:48 AM
@sa3ido 1. Use tags for the prefab. 2. If GameObject go = GameObject.FindGameObjectWithTag("your_tag") returns a null, it doesn't exist in the hierarchy. 3. in that case move on to the next level.
Your answer
Follow this Question
Related Questions
3rd person to 1st person view with two engines 0 Answers
In roll a ball the ball go to outside the wall why any one ans me 1 Answer
FMOD FAILED TO INITAILIZE THSI MAY BECAUSE OF YOUR SOUND 1 Answer
Character controller stops walking in middle of air 0 Answers
How to detect what layer is colliding 0 Answers