Search Unity

InActive Gameobject

Discussion in 'Multiplayer' started by Livindaki, Jul 26, 2019.

  1. Livindaki

    Livindaki

    Joined:
    Jun 13, 2017
    Posts:
    49
    when i use GameObject G=GameObject.Find("The_Room");
    it doesnt get it ..cause its inactive .
    how can i get it ?
    it give me an error :
    NullReferenceException: Object reference not set to an instance of an object ....
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    1) When you instantiate the object, cache a reference to it. Use that reference instead of Find.
    2) If the object is a part of the scene itself, create a reference to it on a script on another object. Use that reference instead of Find.
    3) Instead of making the object inactive, disable all its components but leave the object active. Find will be able to find it.
     
  3. mimat18

    mimat18

    Joined:
    Feb 16, 2019
    Posts:
    12
    Thanks a lot for your help.