Possible to save and load global blackboards?

FlowCanvas Forums Support Possible to save and load global blackboards?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2580
    elvisish
    Participant

    I’m using global blackboards as a way to keep objects persistent between scenes, is it possible to save the blackboard information to a file and load it? I’d like to be able to do this via Flowcanvas rather than writing my own script or using a save asset, but I’m entirely sure if this is posible?

    #2583
    Gavalakis
    Keymaster

    Hey,

    Blackboard variables (and Global Blackboard variables) can be serialized and deserialized (save/load) to a string (text) format and thus a file, but there is no “all-in-one” node to achieve this, thus many smaller node will need to be used (for creating the file, serializing the blackboard, writing the string to the file etc), so this can become a bit complex.

    On the other hand, there is a simpler solution (which might or might not work in your case), that being the ability to save/load the blackboard variables to/from Unity’s PlayPrefs instead. This can be achieved with the ‘Blackboard.Save’ and ‘Blackboard.Load’ functions respectively. Thus to call those functions in flowcanvas, all you have to do is drag&drop the Blackboard into the flowscript Graph Editor as normal, and from the menu that will popup, select the ‘Blackboard/Save’ or ‘Blackboard/Load’ function. Both Save and Load functions require a “Key” parameter. This is simple a text to identify the save and will need to be unique and the same when you want to Save and Load the same blackboard.

    Having said all that, please note that Global Blackboards also have a “Dont Destroy On Load” option (which is checked by default). So, if your goal is to keep the variables consistent between scenes only, then you won’t really need any of the above. If the goal is to keep the variables consistent between entirely different game sessions instead (like a save/load system), then the solution stated above is indeed useful.

    Let me know if the above works for you.

    Thanks šŸ™‚

    Join us on Discord: https://discord.gg/97q2Rjh

    #2584
    elvisish
    Participant

    Hey, Blackboard variables (and Global Blackboard variables) can be serialized and deserialized (save/load) to a string (text) format and thus a file, but there is no ā€œall-in-oneā€ node to achieve this, thus many smaller node will need to be used (for creating the file, serializing the blackboard, writing the string to the file etc), so this can become a bit complex. On the other hand, there is a simpler solution (which might or might not work in your case), that being the ability to save/load the blackboard variables to/from Unityā€™s PlayPrefs instead. This can be achieved with the ā€˜Blackboard.Saveā€™ and ā€˜Blackboard.Loadā€™ functions respectively. Thus to call those functions in flowcanvas, all you have to do is drag&drop the Blackboard into the flowscript Graph Editor as normal, and from the menu that will popup, select the ā€˜Blackboard/Saveā€™ or ā€˜Blackboard/Loadā€™ function. Both Save and Load functions require a ā€œKeyā€ parameter. This is simple a text to identify the save and will need to be unique and the same when you want to Save and Load the same blackboard. Having said all that, please note that Global Blackboards also have a ā€œDont Destroy On Loadā€ option (which is checked by default). So, if your goal is to keep the variables consistent between scenes only, then you wonā€™t really need any of the above. If the goal is to keep the variables consistent between entirely different game sessions instead (like a save/load system), then the solution stated above is indeed useful. Let me know if the above works for you. Thanks šŸ™‚

    That’s really great information, I feel like I’m on the right track! Using PlayerPrefs sounds very convenient, out of curiosity, how much work is involved with saving to an individual file instead of the registry? Can it still be done from FC, or might it require a custom script to handle the serialization? You mentioned creating the file, serializing the blackboard, writing the string to the file, is this reasonably simple to do within Flowcanvas?

    #2592
    Gavalakis
    Keymaster

    Hello again,

    Yes, it is possible to be done with FC as well. Here is an example of how:

    SaveLoadToFile

    • The Serialize and Deserialize nodes are functions of Blackboard and thus you can add those by drag&drop the Blackboard component in the editor and selecting the methods Serialize and Deserialize respectively.
    • For the File WriteAllText and ReadAllText you will need to add “System.IO.File” class in your Preferred Types Editor so that you can see and use File methods in your node browser (in this case were need only these two methods).
    • On the left side we just use some nodes to create a file path for the file to be saved at. This can be done in numerous other ways as well.

    šŸ™‚

    Join us on Discord: https://discord.gg/97q2Rjh

    Attachments:
    You must be logged in to view attached files.
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.