Original Discord Post by petroslouca | 2024-10-01 20:45:04
Hello,
I am using the latest version of Convai SDK in Unity3D 2022.3.21f1 and I would like to clear the Chatbox dialogue text list completely.
There is a public function in ChatBoxUI.cs (attached to the Convai Transcript Canvas prefab that I am using), called ClearUI, see below, but calling it the dialogue is not cleared:
public void ClearUI()
{
foreach (Message message in _messageList) Destroy(message.TextObject.gameObject);
_messageList.Clear();
}
Could you please help me on that?
Also, is there a recommended way to disable the “thumbs up” icons/functionality in the chatbox completely?
Thank you K3! I modified the code in ChatBoxUI.cs script as follows based on <@433610960725344267>'s suggestion:
///
/// Clears all messages from the UI.
///
public void ClearUI()
{
//foreach (Message message in _messageList) Destroy(message.TextObject.gameObject);
//_messageList.Clear();
// Convai Discord suggested custom code for clearing UI (PL)
for (int i = _messageList.Count - 1; i >= 0; i--)
{
Destroy(_messageList[i].TextObject.gameObject);
}
_messageList.Clear();
}
I am calling the function as follows:
//Clear ChatUI from all messages
GameObject.Find(“Convai Transcript Canvas(Clone)”).GetComponent().ClearUI();
But the chat box is not cleared, am I missing something?
Unfortunately that did not work for me, I used the following function to iterate and destroy each chatbox message:
public void DestroyAllChatBoxUIMessages()
{
// Find the ChatBox's child GameObject "Content"
GameObject chatBox = GameObject.Find("Content");
if (chatBox != null)
{
// Loop through each child of the ChatBox
foreach (Transform child in chatBox.transform)
{
// Check if the child's name is "ChatBox(Clone)"
if (child.gameObject.name == "ChatBox(Clone)")
{
// Destroy the child GameObject
Destroy(child.gameObject);
}
}
Debug.Log("All ChatBox(Clone) gameobjects destroyed!");
}
else
{
Debug.LogWarning("ChatBox(Clone) GameObject not found.");
}
}