Saving Trigger State

A few lessons back Sam had challenged us to save the trigger state of the event. I successfully did it for just a simple Save/Load but when I exit and return to the scene it doesn’t save the state.
using RPG.Saving;

using UnityEngine;

using UnityEngine.Playables;

namespace RPG.Cinematics

{

public class CinematicTrigger : MonoBehaviour, ISaveable

{

    bool alreadyTriggered = false;

    //Sets up the animation controls to make sure player can or cant move

    private void OnTriggerEnter(Collider other)

    {

        if (!alreadyTriggered && other.tag == "Player")

        {

            GetComponent<PlayableDirector>().Play();

            alreadyTriggered = true;

        }

    }

    public object CaptureState()

    {

        return alreadyTriggered;

    }

    public void RestoreState(object state)

    {

        bool alreadyTriggered = (bool)state;

    }

}

}

I did have the trigger responsible for this renamed its serial ID to trigger.

Fixed. Solution is at the bottom of my code.
bool alreadyTriggered = (bool)state;
needs to be just
alreadyTriggered = (bool)state;

1 Like

Privacy & Terms