# NullReferenceException in Unity

**URL:** <https://forum.convai.com/t/nullreferenceexception-in-unity/2818>\
**Category:** Unity SDK\
**Tags:** question, unity, bug\
**Created:** [February 4, 2025, 4:03pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818 "2025-02-04T16:03:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![info\_AM](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/info_am/32/2984_2.png) [@info\_AM](https://forum.convai.com/u/info_AM)\
**Post date:** [February 4, 2025, 4:03pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/1 "2025-02-04T16:03:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [February 6, 2025, 8:34am UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/2 "2025-02-06T08:34:06Z")

</div>

Hello @info_AM,

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

---

<div class="post-metadata">

**Author:** ![info\_AM](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/info_am/32/2984_2.png) [@info\_AM](https://forum.convai.com/u/info_AM)\
**Post date:** [February 6, 2025, 9:09am UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/3 "2025-02-06T09:09:28Z")

</div>

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:

```auto
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!");
            }
        }

```

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [February 7, 2025, 12:00pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/4 "2025-02-07T12:00:42Z")

</div>

Could you please share your UI design?

---

<div class="post-metadata">

**Author:** ![info\_AM](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/info_am/32/2984_2.png) [@info\_AM](https://forum.convai.com/u/info_AM)\
**Post date:** [February 7, 2025, 1:50pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/5 "2025-02-07T13:50:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [February 7, 2025, 2:05pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/6 "2025-02-07T14:05:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![info\_AM](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/info_am/32/2984_2.png) [@info\_AM](https://forum.convai.com/u/info_AM)\
**Post date:** [February 7, 2025, 6:13pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/7 "2025-02-07T18:13:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![K3](https://yyz2.discourse-cdn.com/flex004/user_avatar/forum.convai.com/k3/32/2611_2.png) [@K3](https://forum.convai.com/u/K3)\
**Post date:** [February 7, 2025, 7:28pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/8 "2025-02-07T19:28:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex004/uploads/convai/original/1X/e60ef96aa7334c5ccf6682f6c6dbc20fcfa96b49.png) [@system](https://forum.convai.com/u/system)\
**Post date:** [March 9, 2025, 7:28pm UTC](https://forum.convai.com/t/nullreferenceexception-in-unity/2818/9 "2025-03-09T19:28:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
