[Solved] Text not appearing in game depending on the order in the script?

So I’m trying to make it so you can choose the min range and max range before the game. Now I think I have a pretty good idea on how I’m going to do it, and it of course involves a lot of typing text in the script to appear in the UI. You can see the text I have below:

So the problem is, depending on the order, some of the text appears in game while some remain blank. As of it’s current order, “maxGuess.text = max.ToString ();” and “minGuess.text = min.ToString ();” appear in game, the other two don’t. But if move, say “text.text = guess.ToString();” to the top, that will appear in game while the other three stay blank. I think it’s something to do with them being in different scenes, since “minGuess” and “maxGuess” both appear when they’re at the top.

Here are three screenshots of each scene I want the text in, if it will help.

Hope that all made sense. So is this simply a limitation, or is there something I’m missing? I’d appreciate any help with this.

Is that the full script? I’m assuming not, if it is, there is a closing curly brace missing at the bottom of your class.

The third screenshot, the one showing the error, doesn’t have three of the Text UI game objects dragged into the exposed fields. If you are still running code which then tries to access the .text property of those Text UI game objects, you will get a null reference exception error - because the object is missing - like the one you have.

In fact, you have the same issue on all three screenshots. I think your code is simply erroring out before giving you what you expect as a result.

Heh, no it isn’t full code, but I didn’t think the rest was relevant.

Ah, so that’s what that Null Reference error meant. Well, I mean I can’t drag… wait a minute.

Got it working! I prefabbed all the Text UI objects and dragged them in the exposed fields in each scene. Thanks!

1 Like

You’re welcome.

An alternative would be to put some if statements around your code where you try to access the Text UI objects, so in each case you only try to access the ones that actually wxist in the Hierarchy. :slight_smile:

Privacy & Terms