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:
public GUIText nameBox;
void Start()
{
Debug.Log("I am here");
nameBox = GameObject.Find("SquadMembersName").GetComponent<GUIText>();
Debug.Log("check: " + nameBox.name);
Debug.Log("Now here");
}
and when I run this I get:
I am here
check: SquadMembersName
Now here
So the code is clearly doing what you’d expect. But when I run the build, I get errors in my output.txt:
I am here
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
BattleGUI:Start()(Filename: C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/StandalonePlayer/UnityEngineDebug.cpp Line: 34)
NullReferenceException: Object reference not set to an instance of an object
at BattleGUI.Start () [0x00000] in :0(Filename: Line: -1)
any suggestions as to why the GameObject.Find isn’t working?