Unable to save control parameters for cutscenes

Hi!
There is a problem that has been bothering me for a long time. I try to use an int parameter to control the playback of cutscenes. After writing the ISaveable interface, no matter how I modify it, I cannot save this parameter. Please help, thanks!

using UnityEngine;
using UnityEngine.Playables;
using RPG.Saving;
namespace RPG.Cinematics
{   

    public class IntroCinematic : MonoBehaviour, ISaveable
    {   
        int triggerIndex;
        private void Start()
        {
            triggerIndex = 0;
        }
        private void Update()
        {   
            if(triggerIndex == 1)
            {
                GetComponent<BoxCollider>().enabled = false;
            }
            print(triggerIndex);
            
        }
        private void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag == "Player")
            {
                GetComponent<PlayableDirector>().Play();
                GetComponent<BoxCollider>().enabled = false;
                triggerIndex = 1;  
            }
        }

        object ISaveable.CaptureState()
        {
            return triggerIndex;
        }

        void ISaveable.RestoreState(object state)
        {
            triggerIndex = (int)state;
        }
    }
}

Do you have a SaveableEntity component attached to the same GameObject as the IntroCinematic? It’s the interface between the SavingSystem and ISaveabes.

OMG I forgot to add this component :sweat_smile: Thank you!

When I took the course, I did the exact same thing!

I found another mistake of mine, I dragged the PersisitentObjectPrefab directly into the Hierarchy, which led me to the problem of MissingReferenceExcpetion and the scene repeatedly loading, I searched for these and got inspiration from your answer, I deleted the PersisitentObjectPrefab in Hierarchy and everything is normal again, thanks for your professionalism!

That is another common error, partly because it seems counterintuitive NOT to have the items in your scene. The way that Unity manages DontDestroyOnLoad (by putting them in a parallel scene at runtime, means that the current scene is searched FIRST, and your items are found in the scene version, which automagically goes away when you switch scenes, causing errors when you get to the next scene. Good job finding that and fixing it!

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

Privacy & Terms