Null ref on scene 2

So i found a bug with InteractWithUI(), when i start the game from scene 2 instead of scene 1 i get a NullReferenceException: Object reference not set to an instance of an object for the InteractWithUI() section of the player controller. And it disables my ability to click or anything. I’ve checked my code but but seems to be correct.

        private bool InteractWithUI()
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                SetCursor(CursorType.UI);
                return true;
            }

            return false;
        }

Where exactly is the error? Is there an EventSystem object in the scene?

Looks like its on the Player, dont see any Event Systems

Yea, I’m interested in which line line 86 is. I suspect it’s the EventSystem.current.IsPointerOverGameObject() line, but I don’t know without the line numbers or full code listing (so I can count the lines)

I also don’t see an EventSystem in the scene. It could be there, folded into a collapsed object hierarchy but if not, you need to add one

that is line 86, which makes me think im missing EventSystem in the scene

They’re usually added when you create a Canvas, but you can also right-click and add one like you would add any other game object.

I went in and added a GameObject > UI > EventSystems and its working now. Sometimes just talking through things is useful! thanks!

Great!

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

Privacy & Terms