Search Unity

Chat text not showing up

Discussion in 'Scripting' started by RickP, Jan 21, 2020.

  1. RickP

    RickP

    Joined:
    Apr 4, 2010
    Posts:
    262
    In my multiplayer game I have a chat area which is a scroll view control that comes with Unity. It was working at one point but now it's stopped and I'm not sure why. I have a prefab of a text component and I make that the child of the Content part and I don't get any errors but I don't visually see anything. I was wondering if anyone could see anything obvious. The network part is working just fine. It gets to this call, and even goes into this call on the client that is sending the text so it shows visually on their screen too so in that case there is no networking involved for that client and I still don't see the text.

    Note that chatPanel is actually the Content area of the scroll view control.

    Code (CSharp):
    1.     public GameObject chatPanel;
    2.     public GameObject chatTextInstance;
    3.     public GameObject inputChat;
    4.     private List<Message> chatMessages = new List<Message>();
    5.  
    6. private void SendMessageToChat(string text)
    7.     {
    8.         if(chatMessages.Count >= 25)
    9.         {
    10.             Destroy(chatMessages[0].TextObject.gameObject);
    11.  
    12.             chatMessages.RemoveAt(0);
    13.         }
    14.  
    15.         Message newMessage = new Message();
    16.  
    17.         newMessage.Text = text;
    18.  
    19.         GameObject newText = Instantiate(chatTextInstance, chatPanel.transform);
    20.  
    21.         newMessage.TextObject = newText.GetComponent<Text>();
    22.  
    23.         newMessage.TextObject.text = newMessage.Text;
    24.  
    25.         chatMessages.Add(newMessage);
    26.     }
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    If you look in the hierarchy, do you see the text message object there? If so, then it's probably an issue with the text object itself. Try resizing the text objects or the font size on them - if the objects are too small the text won't show up. Maybe something is going wrong with your layout control object on the parent.
     
    Joe-Censored likes this.
  3. RickP

    RickP

    Joined:
    Apr 4, 2010
    Posts:
    262
    I forgot you can see that in real-time in unity.

    Well it shows up as a child but while running if I go to scene it shows these instances off to the right of the actual viewport content area which is why I don't see it. Not really sure why it's going over there. It used to work just fine and I don't recall changing anything with it.

    I have Vertical Layout Group and Child Alignment is set to Lower Left. When I change it in ream-time to lower right it's showing up for some reason but that wasn't the cast before. The anchor must have changed on the chat text prefab object to the right side vs the left.

    [EDIT]
    No the prefab instance has the anchor on the top left but when it's instantiated for whatever reason the anchor changes to top right. That doesn't make much sense.

    [EDIT]

    I'm following this video (
    ) and right at this time when he makes a new Text ui object as child to Content his shows up in the Content view area aligned to the left like expected (which mine did a month ago when I followed this). However if I now create a new Text ui object the entire thing shows up right of the Content window outside of the content area completely.
     
    Last edited: Jan 22, 2020