How to save/load graph in game at run time.

NodeCanvas Forums General Discussion How to save/load graph in game at run time.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #8808

    Perhaps this question has been answered before.
    Can someone point me to a link of how this can be done.

    Cheers.

    #8813
    Gavalakis
    Keymaster

    Hello,

    Can you please clarify what you mean by save?
    Do you mean saving the serialized graph to json?

    Thanks

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

    #8812

    Sorry was not very clear in the question.

    Yes, I mean serialize to json. I understand how to serialize the graph to json, but not clear about deserializing the json back into the graph at run time. While my game is running, I would like to pull in the json from an asset bundle or http get and then have NodeCanvas deserialize it into the graph.

    Btw, what is the best way to serialize/deserialize a graph using asset bundle? Does the graph have to be serialized into json?

    Cheers.

    #8811
    Gavalakis
    Keymaster

    Hello,

    No problem 🙂

    So, there are basicaly two functions in the Graph class. Serialize and Deserialize.
    To deserialize a graph from a json string it’s actualy a matter of calling Deserialize on a Graph reference:
    graph.Deserialize(string json);

    The graphs are always serialized/deserialized from/to json behind the scene. Can you please clarify your question about asset bundles?
    Are you encountering any issues with letting the serialization work automaticaly for you?

    Thanks!

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

    #8810

    Hello,

    I am looking for a bit of clarification on the Serialization/Deserialization of graphs here. What does Graph.Deserialize() do?
    – does it create a brand new graph from the connections/node in the JSON string?
    – or does it *update* the current graph from the JSON data (like current state, elapsed time on all the nodes)?

    Basically, I’m wondering how to save/restore the *state* of a *running* graph during play. For instance, let say the current node has a Wait on it with 0.2s left on a 1s timer (Wait time = 1s with 0.8s on the elapsed time). On restore, the graph needs to set the active node to the one with Wait action (if it is not the Start node) and set the elapsed time on it.

    Clearly, this is a simple example, more complex actions can have more advanced internal state.

    Cheers,
    Alain-Daniel

    #8809
    Gavalakis
    Keymaster

    Hello,

    Graph Deserialize, loads up/updates the current graph from the JSON data. It does not create a new graph.

    Unfortunately what you are after though is not really supported since such data (like elapsed time of a node) are not serialized.
    What is supported instead, is to save/load the blackboard variables, thus you could restore the state of the AI object this way, but of course not the internal state of each action, like for example the elapsed time of an Wait action task or the current running node.
    Instead the BT will re-execute from start, but considering that it is parametrized with variables, it would kind of “restore” it’s state based on those variables.

    Does this suffice for your case?

    Thanks

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.