Text moved after I clicked play

I just found a very strange bug. I just created a new script for the QuizCanvas object from Quiz Master 2D Unity instructed by Gary. After I click play, the script should use the provided method to change question text to the designed question. Well, the question was changed, but it appeared on the top of the canvas. You can’t see this in the game view. I had to switch back to the scene view to spot it.

Capture

It seems that the new script was the problem. Because if I check it off, everything is normal when I click play.
off
Here

Hi Tim,

Are there any error messages in your console when the question disappears? If not, use Debug.Logs in your code. Maybe your code assigns an empty string to the text property. Since we fetch data from other objects, it is impossible to see what’s going on during runtime just by reading the Quiz code. If the string is empty, check where the Quiz object is getting the question text from. Maybe there is no text but an empty field.

I hope this helped. :slight_smile:


See also:

Hi Nina,
I didn’t find any error message. However, I think I’ve realized what the problem was. So when I clicked play, the text was changed, but along with that, the preferred width and height also changed to 1100 and 5315. How can I keep these two parameters unchanged?

You can see the text was changed from the default text (“The is the initial text for question.”) to the question (“In what year did Columbus discover America?”), this is what I want. But the preferred width and height were also changed to these very large values, so the text was rendered in this new text box defined by the width and height.

Hi Nina,
I don’t know how it worked, but I managed to take care of it, sort of. I just selected Top for text alignment, so now in default state the default text will of course be at the top of the text box. But when I click play, the text gets changed as I’ve planned and remains at the top position of the text box, so at least it’s still inside the text box. Bottom and Middle will put text outside the canvas like before, only Top works. This is just so weird, it doesn’t make any sense. Hopefully, when I get better at it someday, I will find out why.

Thanks,
Tim

Good job on fixing the problem!

I do not know what exactly you used in your project but if you used the layout components, that would explain why the TMP bounding box changed its dimensions automatically. It can be a bit tricky to find the right settings for one’s GUI layout in the game. :slight_smile:

I basically have to relearn this stuff every time I open Unity and try to modify the GUI in my games. And I’ve been working on my games for many, many years.Unity’s layout components are probably the only things in my life that I’ll probably never fully understand, no matter how hard I try. :confused:

Thank you for sharing your thoughts and experience, I will make note of the trickiness of layout components.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms