03.5 Objects Save Data
This is an Advanced way of Expanding FPS Engine´s Save & Load Functionality.
This section contains various scripts for handling data saving, particularly for objects. The key script to focus on is CustomSaveData
, as it forms the foundation of the Save & Load system. Only CustomSaveData
can be saved, with the exception of certain Player Properties.
This section contains various scripts besides CustomSaveData. They all override the InteractedState() method or, for triggers, the TriggeredState() method.
What´s InteractedState () & TriggeredState(). How to override them.
InteractedState & TriggeredState ( only for those classes that inherit from Trigger ) define the state of an object when loaded. For example, if a Weapon Pick up has been already picked up, when loading that information, we want to destroy the Pickeable, since it should not exist there anymore.
You should pay attention to very often used variables like interacted for Interactables & triggered for Triggers, since those are always stored into the Json File.
Next, you can find an example of how to override these methods for your custom Implementations:
// Open or close the door based on whether it is interacted or not
// InteractedState is called after loading
public override void InteractedState()
{
// If we interacted with the door, it means it is opened
if (interacted)
{
doorPivot.position = initialPos + offsetPosition;
doorPivot.localRotation =
Quaternion.Euler(new Vector3(
doorPivot.localRotation.x,
openedDoorRotation * side,
doorPivot.localRotation.z));
}
else // If interacted is false, the Door is closed.
{
doorPivot.position = initialPos;
doorPivot.rotation = closedRot;
}
}
CustomSaveData
Last updated