Blackboard – Object References & Serialized Variables

NodeCanvas Forums Support Blackboard – Object References & Serialized Variables

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14716
    w
    Participant

    Hi there,

    Our project uses a multi-scene setup and very often we need to point blackboard variables to objects in different scenes. We use the AMS plugin and have our own resolver to handle those references from blackboards.

    it worked well until the recent 3.0 release, in which blackboards seem to be serialized differently, since our resolver doesn’t know how to handle the new SerializedVariables field though they look the same as ObjectReferences in our cases.

    Your note in blackboard.cs makes sense but what do you think would be the best thing to do to fix our resolver?

            ///Remark: We serialize the whole blackboard as normal which is the previous behaviour.

    ///To support prefab overrides we now also serialize each variable individually.

    ///Each serialized variable has it’s own list of references since it can be an object with multiple

    ///UnityObject fields, or simply a list of UnityObjects.

    ///We keep both old and new serializations. If something goes wrong or needs change with the new one,

    ///there is still the old one to fallback to.

    1. Ignore SerialziedVariables for now, restore cross-scene references from ObjectReferences field. or

    2. Ignore ObjectReferences, restore cross-scene references from SerialziedVariables. or

    3. Handle both cases, and if so, what exactly should I do?

     

    Thanks!

    #14717
    Gavalakis
    Keymaster

    Hello there,

    Indeed, in v3 blackboard serialization has changed. Instead of loading references from the “_objectReferences” list, now variables are serialized separately (as in a SerializationPair class) and each one has it’s own “_references” list to load object references from. The old serialization is still there only for fallback (as well as upgrading).

    Thus, you will only need to handle references from the new ‘_serializedVariables’ field in Blackboard.cs (your #2 solution).

    Please let me know if that works for you, or if you need any more help with that.

    Thanks!

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

    #14723
    w
    Participant

    Hi Gavalakis,

    Thank you for your fast response.

    Just in case you are not super familiar with AMS, here is how it works:

    • When a cross-scene binding is detected, like when you create a reference from a field to a GO in another scene,  AMS serializes the binding and save it in an AMS gameobject in the scene; (see attachment 1)
    • Whenever cross-scene references need to be restored, like when you reload the scenes, AMS parses all the bindings it previously serialized and assign the referenced objects back to the fields;

    Previously, we created our own blackboard resolver to handle both steps above,

    • in the saving phase, we save the bb variable key name to the AMS object in the “Data” array,
    • in the restoring phase, we add the variable back by calling blackboard.SetVariableValue;
    • there’s also some special care we added to support Lists and Dictionaries in blackboard.

    So as you suggested, with a little change to our current code, solution 2 would work.

    However, after digging a little deeper in both NodeCanvas and AMS code, I believe it is possible to make AMS support NodeCanvas out of the box, because basically all the default AMS resolver does is assigning the deserialized referenced object value to the source field via reflection.

    Currently it does not work with Blackboard for some reason as blackboard does not allow adding elements to either the _objectReferences list or the _References field of SerializationPair.  (See attachment 2). I think if blackboard can be updated by manually updating these lists, AMS would work by default.

    Please let me know if this makes sense 🙂

    Thanks again for looking into this.

     

    Attachments:
    You must be logged in to view attached files.
    #14737
    Gavalakis
    Keymaster

    Hello again,

    To be honest, I have no experience with AMS at all, so thank you for the information 🙂

    Setting the references (either _objectReferences, or _references in SerializationPair) directly would not work correctly because those references go on pair with the actual serialization json string. So, even if you set the references via reflection, the reference will be cleared as soon as the variable is serialized again, since by setting the reference there only, it does not also set the variable value.

    So, your original way of doing it (using bb.SetVariableValue) is actually the most correct way as well. That is because doing this, will actually set the Variable value and then as a result of that, when the Blackboard is being serialized, it will store the reference to the _references list.

    I hope this makes sense, but please let me know if not. 🙂

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

    #14749
    w
    Participant

    Got it. It does make sense. I will just switch our resolvers to handle _serializedVariables instead of _objectReferences.
    Thank you Gavalakis.

    #14753
    Gavalakis
    Keymaster

    You are very welcome 🙂

    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.