Problem is not reproducible or outdated
Problems adding text to UI Text Component
I am building up a chat system for multiplayer, and am hitting a very strange wall that I can't explain.
My setup for this is a text field to enter text, and then a UI text object.
For the first message, everything is added to the text object perfectly, however after the first message is sent, or after a script rebuild, no text is added.
I know for certain through debugging that the message is being sent, and received correctly. I also know that the function that is supposed to add the text is also receiving the message correctly.
What's truly bizarre is if I test it offline, being I send the string from the text field straight to the text box, everything works perfectly.
I've also tried using the Concat method as well, same results (unsurprisingly). Full asset re-imports don't help either. The code responsible for adding the string is pretty straight forward:
if (text.text.Length == 0)
text.text += t;
else
text.text += "\n" + t;
"text" is a UI text.
Has anyone seen an issue like this before? Thanks!
Answer by Ignacitus1111 · Oct 07, 2017 at 04:35 PM
Try to use this, the chat is the textbox, and inFi is the input field:
if (inFi.text != "")
{
chat.text += inFi.text;
chat.text += "\n";
inFi.text = "";
}
Hope it works :D
This was solved a while ago, turns out the issue was very deep seeded in the way C# and C handle data types. I had used sizeof (which is a C macro), a few times to get the size of the strings. Because this was networked, there was some encoding involved that used a different data type for char than C understood, this created a massive amount of garbage characters.
Thank you for your answer, but I should close this question.