Hey.
So I’m doing a chat system and the user has the possibility of filtering messages. Basically, I just add the messages within a container and, when the user checks or unchecks a filter, it hides the messages corresponding to the “section”.
Every time I add a message, I set the value of my scrollbar to zero in order to see the last message received. The only thing it’s when I hide some message, the content is not “refresh” (there just is a blank).
I made a GIF just for you

So, as you can see, I add several messages and then I click on “General” in order to hide General messages. The scrollbar does something weird (his size) and the content shows nothing (but there are some messages but we can’t see them because of the mask). But when I move a little bit (with the mouse) the scrollbar, it will be back to the normal…
So I was wondering if you guys have an idea on how to solve this ?
Code:
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Message.eSection randomSection = (Message.eSection)UnityEngine.Random.Range(0, 3);
addMessage(randomSection, "My message comes from " + randomSection, "sbizz");
}
}
public void addMessage(Message.eSection section, string message, string sender = "") {
ChatElements.Filter filter = getFilter(section);
if (filter == null) {
Debug.LogWarning(section + " was not found in the filters list");
}
Text go = Instantiate(_gui.message) as Text;
Message msg = go.gameObject.AddComponent<Message>();
msg.section = section;
msg.dateSend = DateTime.Now;
msg.message = message;
msg.sender = sender;
go.gameObject.SetActive(filter != null && filter._isChecked);
go.transform.SetParent(_gui.containerMessages, false);
go.text = "";
if (printDateNow) {
go.text += "[" + msg.dateSend.ToString("H:mm:ss") + "] ";
}
if (section == Message.eSection.MESSAGE) {
if (sender == "") {
Debug.LogWarning("No sender specified");
}
go.text += sender + ": ";
}
go.text += message;
_messages.Add(msg);
_gui.scrollbar.value = 0;
}
public ChatElements.Filter getFilter(Message.eSection section) {
foreach (ChatElements.Filter filter in _filters) {
if (filter.showType.Contains(section)) {
return filter;
}
}
return null;
}
public void applyFilters(ChatElements.Filter filter) {
foreach (Message message in _messages) {
if (filter.showType.Contains(message.section)) {
message.gameObject.SetActive(filter._isChecked);
}
}
_gui.scrollbar.value = 0;
}