There is a problem with spawning “IChatUI” objects in the “InitializeUI” method in the “ConvaiChatUIHandler” script. I fixed the issue so you can use in next versions.
private void InitializeUI(GameObject uiPrefab, UIType uiType)
{
try
{
IChatUI uiComponent = uiPrefab.GetComponent<IChatUI>();
if (uiComponent == null)
{
ConvaiLogger.Warn($"The provided prefab for {uiType} does not have a component that implements IChatUI.", ConvaiLogger.LogCategory.UI);
return;
}
uiComponent.Initialize(uiPrefab);
GetUIAppearances[uiType] = uiComponent;
}
catch (Exception ex)
{
ConvaiLogger.Exception($"An error occurred while initializing the UI: {ex.Message}", ConvaiLogger.LogCategory.UI);
}
}
When we spawn “IChatUI” objects, “GetUIAppearances” dictionary holds references to the prefabs instead of spawned objects. So if we use the “GetUIAppearances” dictonary to access the IChatUIs, we will get prefabs that are not spawned. I encountered this issue while I developing my project.
I fixed the problem by updating the context of “InitializeUI” method to this:
private void InitializeUI(GameObject uiPrefab, UIType uiType)
{
try
{
IChatUI uiComponent = uiPrefab.GetComponent<IChatUI>();
if (uiComponent == null)
{
ConvaiLogger.Warn($"The provided prefab for {uiType} does not have a component that implements IChatUI.", ConvaiLogger.LogCategory.UI);
return;
}
IChatUI spawnedUI = Instantiate(uiPrefab).GetComponent<IChatUI>();
spawnedUI.Initialize();
spawnedUI.DeactivateUI();
GetUIAppearances[uiType] = spawnedUI;
}
catch (Exception ex)
{
ConvaiLogger.Exception($"An error occurred while initializing the UI: {ex.Message}", ConvaiLogger.LogCategory.UI);
}
}
We don’t need to pass the “uiPrefab” parameter to “Initialize” method of “IChatUI” because it is already itself so we can remove it. We also don’t need the “UIInstance” instance in “ChatUIBase” script for the same reason.