- Home /
UI Variable suddenly not updating when I build and run my project
Hey there I am having a strange issue. I have a variable on my player object that I use to update some score text on my UI Canvas when my player collides with a pickup object. Everything works fine in the editor when you collide with the pickup the variable on the player increments and the text is updated on the UI.
However, When I build and run my game the text on the UI is no longer updated for some reason.
I have a Distance value on my UI that does update all the time which is just based on the change in time.
I call a public method on my player object to get the value to update the score text. Perhaps this is breaking somehow when the game is built?
Has anyone else come across this or does anyone have any idea what might be the issue here?
scoreText.text = (Time.timeSinceLevelLoad * scoreMultiplier).ToString("0");
orbsText.text = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().GetOrbs().ToString();
this code is called in a script that is a component of my canvas object. Scoretext updates fine but orbsText only updates in playmode and not when I build and run the project.
Answer by AaronXRDev · Nov 02, 2018 at 10:18 PM
The first thing I would do is swap the variables. Like this:
scoreText.text = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>().GetOrbs().ToString();
orbsText.text = (Time.timeSinceLevelLoad * scoreMultiplier).ToString("0");
If you find that suddenly scoreText.text isn't updating then it is probably your reference to GameObject.FindGameObjectWithTag that is causing the problem.
If orbsText.text is still not updating then you probably have its location set somewhere on the canvas that shows up in edit mode but is offscreen when it is built. (This is a common problem with mobile projects)
Give that a try and let me know what you find.
Your answer

Follow this Question
Related Questions
How To Put 2 Panel in 1 scene? 2 Answers
Optimal way to display a player's health with hearths? 1 Answer
How to Scaling object with new UI slider ? 1 Answer
Link UI Input Field to Script 2 Answers