Search Unity

Trying to debug error that only appears in standalone build (Gameobject.Find)

Discussion in 'Scripting' started by riadsala, Sep 27, 2011.

  1. riadsala

    riadsala

    Joined:
    Feb 10, 2010
    Posts:
    15
    Hello,

    apologise if this is obvious, or it's covered elsewhere. I had a look on Unity answers, etc,but couldn't find anything. Maybe I'm searching with the wrong keywords.

    Anyway, I've started work trying to implement a gui for my game. I got the general impression that OnGui() is quite expensive so I've started adding in some guiText objects and so on. But for some reason my code works within the Unity3d editor, but not in the build.

    Here's my code snippet:

    Code (csharp):
    1.  
    2.  
    3. public GUIText nameBox;
    4.  
    5.     void Start()
    6.     {  
    7.         Debug.Log("I am here");
    8.         nameBox = GameObject.Find("SquadMembersName").GetComponent<GUIText>();
    9.             Debug.Log("check: " + nameBox.name);   
    10.         Debug.Log("Now here");
    11.        
    12.     }
    and when I run this I get:

    So the code is clearly doing what you'd expect. But when I run the build, I get errors in my output.txt:


    any suggestions as to why the GameObject.Find isn't working?