Error when going from Scene 2 back to Scene 1

So when I go from Scene 1 to Scene 2 everything is working but when I try to go back to my first Scene its giving me this message:

NullReferenceException: Object reference not set to an instance of an object
RPG.Movement.Mover.RestoreState (System.Object state) (at Assets/Scripts/Movement/Mover.cs:98)

    }

        public void RestoreState(object state)
        {
            SerializableVector3 position =(SerializableVector3)state;
            navMeshAgent.enabled = false;
            transform.position = position.ToVector();
            navMeshAgent.enabled = true;
            GetComponent<ActionSchedular>().CancelCurrentAction();
        }

I wonder what’s the problem cause with all other Scenes its working super well.

Which of those are on line 98? state could be null, navMeshAgent could be null, and the result of GetComponent<ActionSchedular>() could be null

I am sorry for not mentioning the line. Its actually the one with the ActionSchedular()

OK, So that means the Mover game object does not have an ActionSchedular. Can you confirm that it does?

well it is the player so yes, it has a ActionSchedular.

if that’s it what you meant :slight_smile:

Is the Mover on the same object?

I’m not sure, but it may be possible that Mover is trying to access ActionSchedular before it’s been created

Yes of course :slight_smile: The Mover Script is also on the same GameObject (Player). I am just wondering why it isn’t working for World 1. When I go back from World 3 to World 2 it is working how it should be. And it is exactly the same setup

Do you have a player prefab in that scene? If the player is marked to DontDestroyOnLoad it will go from scene to scene. If you start a scene with a player prefab already in the scene (like when you are starting on a level) there will be 2 players in the scene: The one that was in the scene from the start, and the one that’s been going from scene to scene.

no my game objective (player) will be destroyed after going into a new scene, there is a new prefab that will be filled with the important information that were provided over the scene change (inventory etc)

OK, but this script cannot find ActionSchedular. Are there other objects in the scene that have a Mover script? Did you accidentally add one somewhere you shouldn’t have? Or forgot to remove one from an NPC?

well that was actually the problem. removing the Mover.cs script from the NPC’s did the trick but the problem is, I need the Mover.cs Script for the NPC’s in order to move. Without it they can’t move. So do I only make sure, that they all have a Mover.cs AND ActionSchedular.cs Script?

The AI Movement is controlled from AIController as it’s different conditional methods to patrol, or chase the player and/or dawdle around in an area effectively animates them for you. I don’t think the Mover.cs was suppose to be included on the Enemies after doing the Prefab variant creation.

Would be able to help out more if the scripts were posted :slight_smile:

No, both the Player and the Enemies need Mover to function correctly.

Both the Player and the Enemies need a Mover, Fighter, and ActionScheduler script to function correctly.

1 Like

Well I forgot to put some Mover.cs Scripts on some of the NPC’s that’s why he did this mistake

1 Like

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

Privacy & Terms