Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Object Null after instatiating.

Discussion in 'Editor & General Support' started by dmitche3, Apr 5, 2014.

  1. dmitche3

    dmitche3

    Joined:
    Apr 3, 2014
    Posts:
    23
    I'm quite new to Unity and I'm stumped at this problem, as well as I can't spell 'instantiating'.
    The script is attached to a child component, if that helps.

    When I instantiate the parent gameobject and I get a run-time error telling me that "it" is null. I say "it" as I believe it is referring to
    myTransform

    But, if the parent object is in the hierarchy at the start the code works fine.

    Any help is appreciated.

    void Start () {
    myTransform = transform; // okay

    guiText = myTransform.transform.Find("GUI Text").guiText; // problem here. if object is present at start of game, okay, but if created after that this is null.
    }
     
    Last edited: Apr 5, 2014