Text Object defaulting to previous value.
I'm trying to add the ability for my users to add notes. I have a list of Note Objects which are basically a string for the note, and an id for what note it is.
When I load my menu, I check my notes list and if the ID matches, it loads the note into the Text objects text property just fine. However, when I set the default menu as inactive and set the notes menu as active, it always defaults the text property back to whatever it was previously, even though it's value is correct before I make it active....
I've tried a few different ways to code how this text is set, but no matter what I do I have the same issue. Is this a Unity querk?
Answer by Optimus_L · Mar 02, 2019 at 09:42 PM
So figured it out.... If anyone finds this and needs an answer you need to change the text of the parent InputField object and not the child text object of the input field.
So where I had a public Text object, I changed it to an InputField and now everything is working great :)
Answer by AaronBacon · Mar 02, 2019 at 04:04 PM
Might be easier to find the problem if you show the code thats enabling, disabling and setting the Note GUI Text. Outside of that, One thing you need to note is that if an object is Inactive, methods like FindGameObjectsWithTag won't be able to find it and therefore set it's text, due to it not being active in the scene. To get around that, you either need to set it in the editor, or just need to have everything enabled on Awake, then disable it as soon as the reference is set.
Again, not sure that's your issue, but it's hard to see the problem when you only show what it Should be doing and not what the code is actually doing.
Because it is inactive when I need to set it, I use a public Text object which I linked up in the editor.
When my menu is called, I set the Text object... string note = NS.ReturnNote (_ID); NoteText.text = note;
$$anonymous$$y Return Note function works fine and returns what I want it to. The NoteText.text = note works fine as well, and when I check the editor, Note Text has the correct note in it when it's inactive and the default view is active.
Then all I'm doing is simply switching between views with buttons that sets the view game objects as inactive and the other view as active. It works for all the other views in the menu...
Even if I do it in the editor, The second I set the Note View game object as active via the lil checkbox, the text in NoteText reverts to whatever the previous value was and I can not figure out why...
Your answer
Follow this Question
Related Questions
Cant find text objects after being renamed. 1 Answer
Text object updating on everything else except for variable 0 Answers
Several objects, same script, different values with no duplications 1 Answer
Can't put a text on an Object 0 Answers
How to display text from a text object to another text object? 1 Answer