Search Unity

Instantiate Question ?

Discussion in 'Scripting' started by MoribitoMT, Dec 29, 2018.

  1. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    301
    Hi,

    When I instantiate a gameobject, I need to access its scripts and give references to some managers. However somehow managers returns null. I can see object created.

    This remind me that maybe the instantiated game object being created much later and managers gets null referecne somehow. I mean this;

    1. GameObject X = Instantiate(X)
    2. Manager.refX = X
    3. Manager.dosomethingwithX // returns null, however I pause screen X is there referenced
    4. Maybe instantiate completed here, and now giving Manager.refX a reference, much later
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Add Debug.Log to scripts in relevant points and use breakpoints in VS to track issue.
     
  3. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    301
    I will do. Just one question, is this possible ? for Instantiate method act like Async method while next line of codes being executed..
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Nope. Unless you put your code on separate thread ans is none GameObject related. But from the first post, it looks, it is not what you try to do.

    May I ask, what you try to achieve?
     
    MoribitoMT likes this.
  5. MoribitoMT

    MoribitoMT

    Joined:
    Jun 1, 2013
    Posts:
    301
    Hey, really thanks for answer. I think I managed to do it, it was becuase of my logic..