• edited October 2020
    Hey,
    Is there a way for me to extract DataObject into string for manual saving, and later construct this? Or ORK is using another superstructure for that?

    Use Case is: I want to save some data based on player profile and not game playthrough.
    For example I want to allow player to create create a preset combatants to reuse later in arena battles.

    Edit: Digging into source code I found the protected function SaveFile() in SaveGameHandler.cs
    Is it possible to use this to save my custom setting/Combatants only? To create sort of GameProfile settings file?
    Post edited by hellwalker on
  • I'm not sure if that's already available in the last version, but the DataObject has a ToXML function to get a string representation of the data, which can be used with ORK's XMLParser to reconstruct the data.

    Otherwise, you can use the GetDataFile function to get an ORKDataFile, which contains the XML data and referenced assets (but that's only for editor-related settings that are saved and e.g. not used/filled by savegames).
    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!
  • edited October 2020
    Thank you! That looks like it worked.
    In case anyone is wondering I made one general DataObject to save overall game settings and information. In here I saved profile Specific DatabObject so I can let player switch profiles.
    And in this profile Data objects I'll save all the profile information. Including the ID range for saved games associated with this profile for custom save/load menu.

    DataObject GameData;
    DataObject CurrentProfileData;
    int CurrentProfileID = 0;
    List<int> ProfileIDs = new List<int>();

    private void InitSettings()
    {
    GameData = ORK.SaveGame.LoadFileShortcut(SaveIndexStart);
    bool _IsSaved = false;
    GameData.Get("IsSaved", ref _IsSaved);
    if (!_IsSaved || Reset)
    {
    GameData = new DataObject();
    CurrentProfileData = new DataObject();
    GameData.Set("CurrentProfileID", CurrentProfileID);
    ProfileIDs.Add(CurrentProfileID);
    GameData.Set("ProfileIDs", ProfileIDs.ToArray());
    GameData.Set("IsSaved", true);
    ORK.SaveGame.SaveFileShortcut(SaveIndexStart, GameData.GetDataFile("savegame"+SaveIndexStart, false).GetXML());
    }
    else
    {
    int[] _Array = null;
    GameData.Get("CurrentProfileID", ref CurrentProfileID);
    GameData.Get("ProfileIDs", out _Array);
    ProfileIDs.AddRange(_Array);
    GameData.Get("Profile" + CurrentProfileID, ref CurrentProfileData);
    }

    }

    Post edited by hellwalker on
  • Hi,
    It's not possible to modify data in DataObject ?
    For example when I called Set() function a second time with same key I got the Dictionary Error.
    ArgumentException: An item with the same key has already been added. Key: AppearanceData
    System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <fb001e01371b4adca20013e0ac763896>:0)
    System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <fb001e01371b4adca20013e0ac763896>:0)
    ORKFramework.DataObject.Set (System.String key, ORKFramework.DataObject value) (at <04749f5db1584516958b98102179bf4e>:0)
  • There should be a remove function you need to use to remove the data first.

    I've removed the automatic value replacement for performance optimization reasons, since ORK never puts in the same key/value twice anyway. Due to the huge amount of data that's stored in an ORK project save this already had a huge impact on faster project save times :)
    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!
  • edited December 2020
    Hey, I'm trying to re-save a string array and I'm having trouble deleting it so I can use set again.


    I tried these two things:


    CurrentProfileData.RemoveArray<string[]>("ArenaRunIDs");
    CurrentProfileData.Set("ArenaRunIDs", _ArenaRunIDs.ToArray());



    CurrentProfileData.Remove<string[]>("ArenaRunIDs");
    CurrentProfileData.Set("ArenaRunIDs", _ArenaRunIDs.ToArray());


    and after both I get this error
    ArgumentException: An item with the same key has already been added. Key: ArenaRunIDs

    CurrentProfileData is a DataObject.
    _ArenaRunIDs is a List list, that I'm saving by calling ToArray().

    Am I doing something wrong?
    Post edited by hellwalker on
  • Works like this:
    CurrentProfileData.RemoveArray<string>("ArenaRunIDs");
    You define the data type of the array's elements, not the array :)
    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!
  • Thanks! That did the trick.
  • edited January 17
    Hello!

    I want to make in custom code the cycle of Start New Game -> Go Back To Title Menu -> Start New Game. And I have a few questions

    1) Is this enough to call a New game on ORK, so all the data gets reset or there is more I should be calling?
    ORK.Game.NewGame(false);

    2) What is the best equivalent of "Going to the title menu so unload the save game and prepare the system for a fresh start" in ORK?
    Or do I even need to do this? Will everything get reset when I either load the save game or start a new game?

    3) This is unrelated to the above.
    But can I retrieve CustomSaveData Dataobject without loading save game ?
    for example would something like this work?


    DataObject _SaveGame = ORK.SaveGame.LoadFileShortcut(_SlotID);
    DataObject _SaveGameSummary = new DataObject();
    _SaveGame.Get("SaveGameSummarySaver", ref _SaveGameSummary);
    Post edited by hellwalker on
  • 1) When quitting the game, either use ORK.Game.LoadMainMenuScene() or at least call ORK.Clear(true, true). You might also need to set ORK.Game.Running = false if you don't load the main menu scene.

    To start a new game, using ORK.Game.NewGame(false) (or true to load the new game scene) is enough.

    2) ORK.Game.LoadMainMenuScene(), clears the game and loads the main menu scene. Not 100% sure if it's needed, as both loading and new game will reset stuff as well - but you should at least set the game to be not running (as shown above) to prevent HUDs from being displayed.

    3) Hm, I don't think so, the function for getting the data object of a saved game is currently not accessible from outside. I can change that in the next update.
    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!
  • Thank you!
    I have a new question. About ORK Object Variables.
    If when I spawned a prefab in the scene, on Awake function I set the Object ID string. Will the Ork Object Variable initialize its saved state based on this string?

    Basically, I'm trying to have a unique ID on scene objects I spawn with code.
  • edited January 20
    The variables (via the object ID) are created/accessed first in the Start function, i.e. changing it in the Awake function should work to use a different ID.

    The easiest way to handle this would probably be to write a custom object variables component for this. Just derive it form ObjectVariablesComponent (namespace ORKFramework.Behaviours) and add the Awake function with your stuff and you're good to go :)

    Just a small hint - if you generate unique IDs, you could just use the Local Variables mode instead, as you'll never have the same IDs anyway, so remembering the variables across scenes or save games doesn't work.
    Post edited by gamingislove on
    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!
  • Thank you!
    I do want to remember them. Basically, what I have Is that you can place snares, traps, and like drill ice fishing holes. So, I want them to persist when you load the game.

    But, since some of the placed items may have multiple states. Like empty snair, snair with rabbit etc. I use ORK object variables component and Game Object Manager to handle this.

    To save all of this runtime placed items, I thought I would create a new RuntimeObjectSaver class. When Item is placed it would register its position and unique ID with this RuntimeObjectSaver class. Then when ORK game is loaded, the RuntimeObjectSaver will spawn these items again, assign ID, Positions etc.

    This should work right? If I spawn an item, assign ID in Awake and then ORK Initializes it in Start it should get the saved information?
  • Yeah, that should work - I've got something similar for saving spawned prefabs. You can download it here. You can use that as a basis for your custom system.

    In short, it's a custom save data that has to be registered at game start and uses nodes to add/remove prefabs, which will automatically be spawned when loading scenes. Shouldn't be too hard add saving their object variables as well :)
    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.