Some questions and requests regarding serialization

NodeCanvas Forums General Discussion Some questions and requests regarding serialization

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13689
    timv
    Participant

    Hi Gavalakis,

    I have a couple of questions/requests regarding serialization:

    I’m using source control and when I load and save a scene without making any changes, NodeCanvas seems to be responsible for some changes in the file. The graph owner’s _graph will be serialized with a different ‘fileID’ and the graph will end up in a different part of the file. All of the data seems to be the same though.
    Would it be possible to make load & save stable?
    It seems the serialized json ends up twice in the scene file. Once as ‘_serializedGraph’ (via Graph), once as ‘boundGraphSerialization’ (via GraphOwner). Are both required or could one be removed? That might solve my first issue.

    Would it be possible to handle fields (member vars) in NodeCanvas tasks and nodes more like Unity handles fields in Monobehaviours?
    – It would be nice to be able to write _myVariable and have it show as “My Variable” instead of “my Variable”. I experimented with using ObjectNames.NicifyVariableName in ReflectedFieldInspector (instead of SplitCamelCase). It does seem to do the trick, but I’m not sure if that will break anything.
    – It would be nice to use private variables and [SerializeField] (or similar) instead of public fields. (Then I can use the same conventions in NodeCanvas code and MonoBehaviours)
    – I would like to be able to use [FormerlySerializedAs(“previousName”)] to rename attributes/arguments of tasks and nodes. I’ve been using this together with Unity’s AssetDatabase.ForceReserializeAssets to convert old content and I would like to do the same to all behaviour trees. Would it be possible to implement such a feature in NodeCanvas?

    Thanks,
    Tim

    #13697
    Gavalakis
    Keymaster

    Hello Tim,

    Hmm. I haven’t came across your first point about ‘fileID’ changing, but I will take a look at this and see what I find. I have a hunch about what could be going wrong here. Regarding the double serialization (‘boundGraphSerialization’ and ‘_serializedGraph’), actually only ‘boundGraphSerialization’ is needed. ‘_serializedGraph’ seems to be stored with the scene due to the hideFlags of the temporary boundGraphInstance that is created in Validate. Changing the boundGraphInstance.hideFlags to DontSave (in Validate method) will probably fix this problem, but I will need to take a much closer look to ensure everything else works as expected as well.

    Please let me address the rest of your questions as well:
    – In the new version (pending review), ‘_myVar’ is now displayed as ‘My Var’, as expected. 🙂
    – Do you mean using private variables with [SerializeField] for exposing in the inspector as well? If so, you can use the [ExposeField] attribute on a private variable to make it show in the inspector.
    – It’s already possible to use the [fsProperty(“previousName”)] attribute which is a property of FullSerializer that NodeCanvas is using. [fsProperty] can work similar to [FormelySerializedAs] attribute. (It can be found in the ‘ParadoxNotion.Serialization.FullSerializer’ namespace). When you are using [fsProperty] by the way, you dont “need” to also use [SerializeField] since it acts the same, but it’s ok if you do though.

    Please let me know if the above work for you.
    Thanks!

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

    #13699
    timv
    Participant

    I changed GraphOwner’s Validate as you suggested and it seems to be working as expected. Only boundGraphSerialization remains in the file and graph’s fileID is set to 0. For context, I’m using Unity 2017.3. I intend to switch to 2018.3 when it is out of beta. I noticed there is a preprocessor #if UNITY_2018_3_OR_NEWER here. Will this behaviour be different in this version?

    In the new version (pending review), ‘_myVar’ is now displayed as ‘My Var’, as expected

    Great!

    Do you mean using private variables with [SerializeField] for exposing in the inspector as well? If so, you can use the [ExposeField] attribute on a private variable to make it show in the inspector.

    Yes, that is what I was looking for, thanks!

    It’s already possible to use the [fsProperty(“previousName”)] attribute which is a property of FullSerializer that NodeCanvas is using. [fsProperty] can work similar to [FormelySerializedAs] attribute.

    I tried this, and the difference seems to be that it will keep serializing the data using the name specified in the attribute, while using [FormelySerializedAs] will use the new name of the variable. It would be nice to be able to update all content (Using AssetDatabase.ForceReserializeAssets) and after that to remove the attributes from code again.

    Thanks!
    Tim

    #13778
    Gavalakis
    Keymaster

    Hello again,

    Thanks for the follow up and confirmation about changing hideFlags. The Unity_2018_3_OR_NEWER preprocessor is there due to the prefabType checking, but if setting hideFlags to DontSave works the same in 2018.3 then there will be no need for that. I still need to do further testing to ensure everything works as expected before changing these though 🙂

    Regarding [fsProperty], it indeed keeps serializing the field with the attribute provided name. For what you suggest, I will need to make something different than what [fsProperty] does. I will take a look at that in a future version (v2.9 just gone live) 🙂

    Thanks!

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

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