- Home /
YAML support?
I'm pretty new to unity, and was wondering if there was a way to read/write to YAML files using the Unity API. I came from coding bukkit plugins (Minecraft Multiplayer server software) and its api had a built in feature that used yaml files. I wanted to see about using .yml files to store some data rather than player prefs or dealing with serialization. I looked on google and the unity documentation and haven't found anything useful, any info would be nice. Thanks.
Answer by Bunny83 · Nov 26, 2015 at 02:51 AM
In short: no. The Unity editor uses YAML for asset serialization but only inside the editor. When you build your project all assets are stored in a binary format as it's smaller and loads faster. The UnityEngine doesn't include any YAML parser or generator. However there are plenty out there.
YAML is not necessarily a good choice for a serialization / data storage format. It's quite "verbose" and if it should be editable by humans its strict structure makes it sensitive for errors. As suggested by McKenzieG1 on the SO question i would also recommend to use JSON instead as it's much simpler and more versatile since it's more common even it has less "features" than YAML.
ps: You said you don't want to deal with serialization, but storing data in a text format is serializing the data. I barely programmed for Minecraft since i don't really like Java ^^. However it seems that Minecraft itself doesn't have support for YAML. Bukkit has added the FileConfiguration class which does this, Minecraft usually used NBT to store data which is actually very close to how PlayerPrefs are stored in a webplayer build. PlayerPrefs just don't support any structures.
Thank you for the answer. I was just wondering since saving strings or floats in YA$$anonymous$$L format would be easy to look up on occasion. I found a way to serialize what I needed, it's just more steps than I would have liked.
Answer by a7BiT-psycho · Nov 26, 2015 at 03:49 PM
There is no built in YAML support. So youd either have to write your own implementation or use a .NET YAML library.
Most users decide to use JSON for saving and loading user data in Unity.
Answer by tacman1123 · Nov 13, 2020 at 01:17 PM
It's worse than it look -- it's a modified YAML format, most yaml parsers will throw an error.
First, it's multiple documents, separated by ---
But there are also duplicate keys, and sometimes line wraps. I'm not sure how they even parse it.
For example, from a .unity (scene) file (note the link break).
m_LightingDataAsset: {fileID: 112000001, guid: fb3c98ad753fd9d4781da879935c9e93,
type: 2}
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
Well, first of all this question was about YA$$anonymous$$L support in Unity. So for runtime use, not to read Unity's own text based asset format which happens to be YA$$anonymous$$L. I'm not sure where you get that "modified" YA$$anonymous$$L format from. The "---" is the official document seperator and they use a label to define the internal Unity type (the "!u!196" after the "---") and a reference (the "&4") to indentify the object in the stream. YA$$anonymous$$L is a beast and highly complex. That's why YA$$anonymous$$L has a few critique points and is generally not considered "portable".
As for the line breaks, that's completely allowed ^^. Just have a look at more complex mapping examples in the specification. Curly braces indicate an inline mapping
I've written my own json parser because json is an extremely simple and robust format. I don't want to write a YA$$anonymous$$L or X$$anonymous$$L parser that satisfies the whole specification. I started writing my own X$$anonymous$$L parser and it's currently on hold because implementing even a subset of the specification is a nightmare. Especially when you think about entities and the billion laughs attack.
You're right, @Bunny83 , my YA$$anonymous$$L parser doesn't support the whole spec.
And there's issues like strings beginning with zero not being quotes, which is being interpreted as octal. Ugh.
Your answer
Follow this Question
Related Questions
Play Services Cloud saving help. 0 Answers
About unity's API for android? 2 Answers
Using the Kongregate API 1 Answer
WWW : Waiting for response from server 1 Answer
Getting 403 Forbidden error when trying to post to FB wall 4 Answers