I am trying to maintain player combatant state across time and runs of my game.
I currently run the following code snippet when initializing my game :

if (ORK.SaveGame.FileExists(0))
DataObject data = ORK.SaveGame.LoadFile(0);
playerCombatant = new Combatant(data, false, ORK.Game.ActiveGroup);
Debug.Log("Loaded Game from Slot 0");
// No previous saved game so create a new combatant.
playerCombatant = ORK.Combatants.Create(
0, ORK.Game.ActiveGroup, false, false);
// Mutate the data slightly.
Debug.Log("PlayerCombatant:" + playerCombatant.Status.Level);
Debug.Log("PlayerCombatant:" + playerCombatant.Status.LevelUp());
Debug.Log("PlayerCombatant:" + playerCombatant.Status.Level);
// Save to slot 0.
// Next time the game runs, I expect the ORK.SaveGame.FileExists(0) call to return true

Currently I get the following stack trace when I run this code :
NullReferenceException: Object reference not set to an instance of an object
ORKFramework.SaveGameChoice.SavedGame () (at <8fa1d1597e124b05acdf108d7df8f4b0>:0)
ORKFramework.SaveGameHandler.Save (System.Int32 index) (at <8fa1d1597e124b05acdf108d7df8f4b0>:0)
MyNamespace.CustomLevelManager.Start () (at Assets/Scripts/CustomLevelManager.cs:52)

I tried finding some code examples or API documentation for SaveGameHandler, but I didn't find anything related to Save(index) and why it failed like above.
  • Well, you load the whole save game and try to feed that into a combatant, so that'll definitely not work and leave a combatant that's probably not initialized correctly.

    Does this also happen when no save file exists?
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.