Object Reference not set to an instance of an object

Hey there.
Just finished the Calculating a NavMesh path and in Scene 1 where we have been doing or code and test, code and test. Everything it working great. Our cursors that we added in the few previous lectures all work, and our movement additions to code all work as well (Can we move here? Is where we want to move to far away?) Both questions work no problem.

The issue I just encountered when I was testing was, I went from Scene 1 to Scene 2. As soon as the 2nd scene loads up the character doesn’t (can’t) move anymore and I get spammed with the error

I checked the code and line 49 of the Player Controller.cs Script is the
if (EventSystem.current.IsPointerOverGameObject()) line

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

The error also points to line 34


which is the line
if (InteractWithUI()) return;

        private void Update()
        {
            if (InteractWithUI()) return;
            if (health.IsDead())
            {
                SetCursor(CursorType.None);
                return;
            }

            if (InteractWithComponent()) return;
            if (InteractWithMovement()) return;

            SetCursor(CursorType.None);
        }

I’m sure it is something simple I overlooked, and I have even gone back a few lectures and made sure the NavMesh is set to walkable, but that as far as my knowledge of problem solving goes. Do anyone have any other ideas I might try, or things I could check??

Thank you so much everyone! Happy Easter! :egg: :rabbit: :sunflower:

Make sure that there is an EventSystem in each scene. It’s likely that the EventSystem is missing from Scene 2.

Added the “missing” EventSystem and now I can move the player character again. Good Call on that Brian, you were right again, that was missing.
But now I’m getting this warning message when I go in-between scenes.


I know these are less “important” errors, but I would like to understand the issue. There is more than enough space where the player spawns into the other scene on the NavMesh, so I don’t know what the issue would be. I set the spawn-in point a ways in front of the “portal” as well, like Sam did in the lesson where we made this originally. I don’t know if this picture will help, but the NavMesh is on and the blue diamond is the spawn-in point and as you can see… NavMesh for days. lol. so… (shrugs shoulders)

Do you have any ideas on what this issue might be?
Thank you so much again Brian.

In the first frame, the character is generally not “precisely” on the NavMesh. By precisely, I mean precisely. Unity throws this warning, and then on the very next frame, the character will be precisely on the NavMesh. You’ll never get it precisely on the NavMesh, as the NavMesh isn’t a “pixel perfect” thing. You can safely ignore this message.

Ok. No worries then. Makes sense and knowing that it’s not game breaking, or that it is something Unity is just warning you about is good news to hear.

Thank you so much again Brian. :+1: :grinning:

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

Privacy & Terms