NullReferenceException in Unity

Hi there, I found a NullReferenceException in Unity:

NullReferenceException: Object reference not set to an instance of an object Convai.Scripts.Runtime.UI.ChatUIBase.DeactivateUI () (at Assets/Convai/Scripts/Runtime/UI/Chat/ChatUIBase.cs:60)

I could fix it by using ‘?’:
UIStatusChange?.Invoke(false);

That is also used in line 50. So I assume that is the correct fix?!
Thanks Rainer

Hello @info_AM,

How did this issue occur? Did you modify any scripts or make changes to the Convai Essentials Prefabs?

Hi @K3 ,
I have an “edit” / Admin mode in my app, where I want to hide the convai UI. I use this code and then it happens when I want to deactivate the UI:

public void SetState(bool state)
        {
            _convaiInputManager.enabled = state;
            _convaiUI.SetActive(state);
            
            if (ConvaiChatUIHandler.Instance == null)
            {
                Debug.LogWarning("ConvaiChatUIHandler component not found!");
                return;
            }
            
            // Hide the ConvaiChatUIHandler currentUI
            IChatUI iChatUI = ConvaiChatUIHandler.Instance.GetCurrentUI();
            if (iChatUI != null)
            {
                if (state)
                {
                    iChatUI.ActivateUI();
                }
                else
                {
                    iChatUI.DeactivateUI();
                }
            }
            else
            {
                Debug.LogWarning("IChatUI component not found!");
            }
        }

Could you please share your UI design?

Hi,
I´m not sure why you would need that. My post is just about a bug I found. I thinks it’s save to use my fix in my project and you should apply the fix to the codebase in general.
I sent this info via email before. I got an answer that I should post it here. Please forward it to a developer. They will know if / what to apply.

Some background: I want to position colliders in the room. Therefore I have an admin mode where I can place Spatial Anchors (meta Quest 3 is used). In this mode I disable convai and the convai UI. Therefore I created the function posted in my last reply.

Thanks
Rainer

Hello,

This event is used by ConvaiLogoHandler.

If you have removed the Convai logo, this issue may occur. The logo can only be removed if your plan is Annual Scale or higher.

For account, billing, or plan-related issues, support email is available only for those inquiries.

Thank you for your feedback! I will share this with our team.

Hi,
no I didn’t do anything to the logo or so. I just found this functionality to hdie the current UI prefab which is visible by getting it with
IChatUI iChatUI = ConvaiChatUIHandler.Instance.GetCurrentUI();
and then hiding the complete UI prefab / gameobject with
iChatUI.DeactivateUI();
Cheers
Rainer

Thanks for sharing the details!
I’ll share these details with our team.
Let us know if you have any other questions!