Saving with Scene Error

Hi,
I get this error (and only this one) when i try to load with the Portal.cs script like seen in the lecture. If i comment the line ‘wrapper.Load()’ in this script, i don’t get the error (and it obviously don’t load).
I saw the other problem regarding this and I also have a portal in the Don’tDestroyOnLoad infinitely like they had. I checked multiple time every scenes to see if there is a SavingSystem, a SavingWrapper or a Fader in my scenes before loading and there isn’t.
I also checked every script if there is differences and i didn’t spot anything except the different naming i did on my own project.

Is there an other possibility i didn’t of that can cause this crash ?

Thank you in advance and sorry for english error.

The error is in line 64 of Mover, so I don’t think it’s a Swaing Wrapper issue. Paste in your Mover.cs, and we’ll take a look.

Mover.cs :


using UnityEngine;
using UnityEngine.AI;
using GameDevRPG.Core;
using GameDevRPG.Saving;

namespace GameDevRPG.Movement
{
    public class Mover : MonoBehaviour, IAction, ISaveable
    {
        [SerializeField] float _maxSpeed = 6f;

        NavMeshAgent _navMeshAgent;
        Health _healthComponent;

        private void Start()
        {
            _navMeshAgent = GetComponent<NavMeshAgent>();
            _healthComponent = GetComponent<Health>();
        }

        void Update()
        {
            _navMeshAgent.enabled = !_healthComponent.IsDead();

            UpdateAnimator();
        }

        public void StartMoveAction(Vector3 destination, float speedFraction)
        {
            GetComponent<ActionScheduler>().StartAction(this);
            MoveTo(destination, speedFraction);
        }

        public void MoveTo(Vector3 destination, float speedFraction)
        {
            _navMeshAgent.SetDestination(destination);
            // Clamp01 permit to be sure that (0 <= speedFraction <= 1)
            _navMeshAgent.speed = _maxSpeed * Mathf.Clamp01(speedFraction);
            _navMeshAgent.isStopped = false;
        }

        public void Cancel()
        {
            _navMeshAgent.isStopped = true;
        }

        private void UpdateAnimator()
        {
            Vector3 velocity = _navMeshAgent.velocity;
            Vector3 localVelocity = transform.InverseTransformDirection(velocity);
            float speed = localVelocity.z;
            GetComponent<Animator>().SetFloat("forwardSpeed", speed);
        }

        public object CaptureState()
        {
            return new SerializableVector3(transform.position);
        }

        public void RestoreState(object state)
        {
            // SerializableVector3 vector = state as SerializableVector3; // Is the same as a cast and don't throw an exception
            SerializableVector3 vector = (SerializableVector3) state;
            _navMeshAgent.enabled = false; // Need to disable NavMeshAgent to move things without him
            transform.position = vector.ToVector();
            _navMeshAgent.enabled = true;
        }
    }
}

With our saving system, Start() is called after RestoreState(). Rename the Start() method to Awake() and _navMeshAgent will be initialized by the time RestoreState() occurs.

1 Like

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

Privacy & Terms