What have you learnt about interfaces?

Has this lecture taught you anything new about interfaces? Did anything click that hadn’t before.

Hello Sam, not know if only me has this issue, seems that after we get responsible the Mover for saving my old good player being stuck on a infinite loop on fade in fade out between scene switch. Basically I did start my scene near a portal, passing by the portal on scene 2 and back again on scene 1. After that my player position saved is already inside the portal collider so I switch again on scene 2 and so on :slight_smile:
For solve this infinite loop inside the Transition on the Portal script just before the savingWrapper.Save() and while fading I reset the position of the player as the portal spawn as in this code:

//Before the saveing of Player position, I reset it to the spawn point of the portal for prevent infinite loop
GameObject.FindWithTag("Player").GetComponent<ActionScheduler>().CancelCurrentAction();
GameObject.FindWithTag("Player").GetComponent<PlayerController>().enabled = false;
GameObject.FindWithTag("Player").transform.position = spawnPoint.position;
GameObject.FindWithTag("Player").transform.rotation = spawnPoint.rotation;

With that seems to work pretty good now, hope it helped someone.

I think this might get fixed.

1 Like

Infact you already fixed it in later section :slight_smile:

The interface made a lot more sense this time around, I think having the extra method and using the Ctrl + . menu to implement the interface made it click.

I was able to add a SaveableEntity script to the “Intro Sequence” object and use the Interface to save whether the cutscene had already played.

I also tried to add the rotation component to the Mover script (and got it to work eventually), but I’m not sure if it’s a good solution. I wasn’t able to use an array, since I wouldn’t adhere to the interface if I tried to pass that back, so ended up going with a Dictionary<string, object>. Is there a better solution than what I stumbled into here?

public object CaptureState()
{
    Dictionary<string, object> moverDict = new Dictionary<string, object>();
    moverDict["position"] = new SerializableVector3(transform.position);
    moverDict["rotation"] = new SerializableQuaternion(transform.rotation);
    return moverDict;
}

public void RestoreState(object state)
{
    Dictionary<string, object> stateDict = (Dictionary<string, object>)state;
    SerializableVector3 position = (SerializableVector3)stateDict["position"];
    SerializableQuaternion rotation = (SerializableQuaternion)stateDict["rotation"];
    GetComponent<NavMeshAgent>().enabled = false;
    transform.position = position.ToVector();
    transform.rotation = rotation.ToQuaternion();
    GetComponent<NavMeshAgent>().enabled = true;
    GetComponent<ActionScheduler>().CancelCurrentAction();
}

Great addition! I hadn’t thought of that.

That’s exactly how I would be doing it. The other option is to create a serializable struct but I find that takes up more code.

var might save you some typing here.

Privacy & Terms