• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Oct 09, 2017 at 03:32 PM by Major for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Major · Aug 04, 2017 at 12:32 AM · multiplayerchatstrings

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Major · Oct 09, 2017 at 03:31 PM 0
Share

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

149 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Global variable 0 Answers

What is the relationship between VR Chat and Unity? 1 Answer

Giving authority to clients 0 Answers

Attack on Titan Multiplayer Problem 2 Answers

Customizing multi player 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges