NodeCanvas Forums › General Discussion › Feature Request: Save to JSON by default
Is saving to JSON possible for you to add as an option (menu option perhaps)
Personally, I hate that so many Unity asset files aren’t able to be compared using GIT or similar, and since there’s already an option for importing/exporting to and from JSON, I think it’d be a great feature for NodeCanvas. I’m not a professional game developer, but I think better collaboration with this would be a huge asset to more professional people (I see Shroud of the Avatar uses this!)
This is probably the biggest feature I’d like from NodeCanvas that I can think of. I notice when opening up behavior trees a lot, the asset file often gets ‘touched’, though I don’t recall moving or changing anything at all. Being able to somewhat see what actually got changed in the history would be really useful for many people I think.
P.S, while I noticed the lack of this a while back, recently I saw another asset with someone similar behaviour to NodeCanvas, DID do have an option for this, so I thought about suggesting it.
Hey,
Do you mean saving to json directly instead of .asset files? So that you would click the text file in the project borwser and open the behaviour tree from there?
Let me know of that other asset so that I understand better what you mean 🙂
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Yes saving to JSON directly, without needing to export. So rather than the serialized asset files that can’t be compared in say, a text editor, it would be a JSON file, then when submitting updates to a repo, they’re easy to compare. Otherwise we only see that a BT or FSM was updated, but don’t know if it was a meaningful update, if a position just got moved half an inch, something was accidentally deleted, etc.
Though, now that I think more on it, there’s probably a Unity coding thing behind why JSON is usually an export format rather than default format for saving things, but fingers crossed…
The asset was Behave 2 I think, though I think when I skimmed over the text yesterday I didn’t read it clearly, it just says ‘No funky runtime data formats or interpretation. Designer -> Compiler -> Your code.’, so I think I was wrong about that. -> https://www.assetstore.unity3d.com/en/#!/content/10912
—
An alternative and maybe more likely idea, if that’s not possible, would be an option to (auto) save a .json file beside the .asset file whenever the .asset file is saved, so that source repos can at least visually compare what changed, and developers will know that the .asset file is tied to the .json.
i.e.
BTsGeneric Soldier.asset
BTsGeneric Soldier.json
BTsGeneric Boss.asset
BTsGeneric Boss.json
Actually, I just happened to purchase Spine ( https://esotericsoftware.com/ ) today and imported their runtime examples, when I noticed they had a .asset file which is editable as a text file, but displays in Unity with properties, attached is a screenshot!
Hey,
This is the Unity YAML format which is possible if the project is set to text serialization under “Project Settings/Editor” > Asset Serialization 🙂
You can open up any .asset file with a text editor. Opening a graph .asset file will also show similar things + the json serialized.
🙂
Join us on Discord: https://discord.gg/97q2Rjh
Ah… The feeling of stupidity…
I’ve been playing around with Unity for a couple months now and had absolutely no idea! It’s my first graphical editor for coding any kind of game, and I had gone through the options previously, but didn’t notice that and assumed it was just a Unity thing, makes much more sense now 😛 Surprisingly, this wasn’t one of the many things that I did search the internet about!
Thanks a lot! /ashamed
Hey, dont be harsh with yourself 🙂
This YAML thing is a very obscured setting/feature and for most people not really useful to know about it 🙂
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Pre-TLDR: Unity’s forced-text serialization YAML is really bad, and breaks imported assets without even telling you. If possible, an option for JSON saving by default (if it’s still select-able as an asset within Unity, such as it is now), or, an option to save a .json file alongside the .asset file, is still on my wish-list for NodeCanvas
I know (from what I read), as a user we can’t selected a specific serialization format for specific asset files, is that possible in code for you to easily switch the asset files to use YAML? Or does it -have- to be Unity’s global setting?
The reason I ask is because while converting my entire project to YAML works alright (aside from unsigned integer errors from Unity 5+), importing third party assets can break (from what I read, and…)
I verified this twice, because the very next package I imported wasn’t working properly, even though no errors are thrown, and I only knew it was an import problem because I had just read about the issue and reverted to a previous git commit to test,
The workaround, I read from the internet, is to switch your project to ‘Mixed Serialization’, import the third party asset, then switch BACK to “Forced Text Serialization”, which all-in-all, is time consuming and a huge pain to be honest.
My real push for having NodeCanvas things saved in a somewhat text readable format for A) git, B) comparing and retaining information, is because NodeCanvas is in effect replacing what we would be writing in code, and your JSON export is really readable. Let me know what you think!
Plus, comparison of NodeCanvas JSON vs Unity’s YAML:
NodeCanvas:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
{ "version": 2.20000004768372, "type": "NodeCanvas.StateMachines.FSM", "name": "Basic Enemy", "comments": "", "translation": { "x": -7911.9990234375, "y": -8005.9990234375 }, "nodes": [ { "_actionList": { "executionMode": "ActionsRunInParallel", "actions": [ { "searchTag": "Player", "saveAs": { "_value": null, "_name": "Player" }, "_isActive": true, "overrideAgent": null, "$type": "NodeCanvas.Tasks.Actions.FindWithTag" |
vs Unity…
1 2 3 |
_serializedGraph: '{"version":2.20000004768372,"type":"NodeCanvas.StateMachines.FSM","name":"Basic Enemy","comments":"","translation":{"x":-7911.9990234375,"y":-8005.9990234375},"nodes":[{"_actionList":{"executionMode":"ActionsRunInParallel","actions":[{"searchTag":"Player","saveAs":{"_value":null,"_name":"Player"},"_isActive":true,"overrideAgent":null,"$type":"NodeCanvas.Tasks.Actions.FindWithTag"}],"_isActive":true,"overrideAgent":null},"_repeatStateActions":false,"_transitionEvaluation":"CheckAfterStateFinished","_collapsed":false,"_position":{"x":8220.0,"y":8130.0},"_name":"Initialize","_tag":null,"_comment":null,"_isBreakpoint":false,"$type":"NodeCanvas.StateMachines.ActionState","$id":"2"},{"_nestedBT":{"_value":null,"_name":"PatrollingBehaviour"},"executionMode":"RunForever","updateInterval":0.0,"successEvent":null,"failureEvent":null,"_transitionEvaluation":"CheckContinuously","_collapsed":false,"_position":{"x":8535.0,"y":8220.0},"_name":"Patrolling","_tag":null,"_comment":null,"_isBreakpoint":false,"$type":"NodeCanvas.StateMachines.NestedBTState","$id":"7"},{"_actionList":{"executionMode":"ActionsRunInSequence","actions":[{"functionWrapper":{"_targetMethod":{"_baseInfo":"Enemy2DController|StopMoving","_paramsInfo":""},"$type":"NodeCanvas.Framework.Internal.ReflectedAction"},"_isActive":true,"overrideAgent":null,"$type":"NodeCanvas.Tasks.Actions.ExecuteFunction"},{"functionWrapper":{"_targetMethod":{"_baseInfo":"Enemy|Jump","_paramsInfo":""},"$type":"NodeCanvas.Framework.Internal.ReflectedAction"},"_isActive":true,"overrideAgent":null,"$type":"NodeCanvas.Tasks.Actions.ExecuteFunction"},{"waitTime":{"_value":0.5,"_name":null},"finishStatus":"Success","_isActive":true,"overrideAgent":null,"$type":"NodeCanvas.Tasks.Actions.Wait"}],"_isActive":true,"overrideAgent":null,"$id":"10"},"_repeatStateActions":false,"_transitionEvaluation":"CheckContinuously","_collapsed":false,"_position":{"x":8610.0,"y":8370.0},"_name":"Saw Player","_tag":null,"_comment":null,"_isB |
(Which you can paste into a JSON beautifier, but it’s still far, far less readable than NodeCanvas’ export I think)
Personaly I haven’t experienced any issue with unity’s “text only” serialization.
In any case, the easiest thing I can do at this point would be save a json file alongside the asset automaticaly (optional setting).
Changing usage of .asset to be .BT for example, is simply not possible at this point without breaking people’s stuff 🙂
There are some other fuzzy ideas that come in mind, but I will have to think them better.
Join us on Discord: https://discord.gg/97q2Rjh
Well in my scenes nothing was broken with the text serialization, but after importing third party assets, their scenes were broken after import, unless I changed it to Mixed serialization before importing them, makes me a bit iffy about using that setting for reliability.
But anyways, that optional setting would be perfect, thanks!
Just curious since I’ve never looked into custom formats on Unity, I’m guessing .asset files have to be in Unity’s own serialization formats?