NullReferenceException: When implementing IsPointerOverGameObject()

This is truly mind boggling. I implemented the changes Sam showed us to check whether we are interacting with the UI or not in PlayerController.cs:

void Update()
        {
            if (InteractWithUI()) return;

which points to:

bool InteractWithUI()
        {
            return EventSystem.current.IsPointerOverGameObject(); // Line 70 in regards to the image below.
        }

and generates this error whenever I try to hit play:

image

If I comment out the first line in update the game works as per usual.

4 Likes

For some reason I must have accidentally deleted the EventSystem object from my main Scene (it was still present in my shortcut scene). So if anyone else ends up being this clumsy I won’t delete my post.

3 Likes

Personally, I recommend putting it in your Persistent Objects Prefab. You can’t accidentally delete it or forget it then.

1 Like

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

Privacy & Terms