
Security News
libxml2 Maintainer Ends Embargoed Vulnerability Reports, Citing Unsustainable Burden
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
This project aims to provide a python3 API to load and dump Unity YAML files(configurations, prefabs, scenes, serialized data, etc) in the exact same format the internal Unity YAML serializer does.
Using this API you will be able to easily manipulate(as python objects) Unity YAML files and save them just the same, keeping the YAML structure exactly as Unity does. This has the advantages of, first not having to configure PyYAML beforehand to deal with Unity YAMLs, and second as the modified file keeps the same structure and formatting that Unity does, when the YAML file is loaded by Unity it won't make formatting changes to it that will make any VCS report unexpected file changes.
Install and update using pip:
pip install -U unityparser
from unityparser import UnityDocument
# Loading and modifying a config file with a single YAML document
project_settings_file = 'UnityProject/ProjectSettings/ProjectSettings.asset'
doc = UnityDocument.load_yaml(project_settings_file)
ProjectSettings = doc.entry
ProjectSettings.scriptingDefineSymbols[1] += ';CUSTOM_DEFINE'
ProjectSettings.scriptingDefineSymbols[7] = ProjectSettings.scriptingDefineSymbols[1]
doc.dump_yaml()
# You can also load YAML files with multiple documents and filter for a single or multiple entries
hero_prefab_file = 'UnityProject/Assets/Prefabs/Hero.prefab'
doc = UnityDocument.load_yaml(hero_prefab_file)
# accessing all entries
doc.entries
# [<UnityClass>, <UnityClass>, ...]
# accessing first entry
doc.entry
# <UnityClass>
# get single entry uniquely defined by filters
entry = doc.get(class_name='MonoBehaviour', attributes=('m_MaxHealth',))
entry.m_MaxHealth += 10
# get multiple entries matching a filter
entries = doc.filter(class_names=('MonoBehaviour',), attributes=('m_Enabled',))
for entry in entries:
entry.m_Enabled = 1
doc.dump_yaml()
# calling entry method for a doc with multiple document will return the first one
print(doc.entry.__class__.__name__)
# 'Prefab'
Main class to load and dump files.
Classmethod: Load the given YAML file_path and return a UnityDocument file
Dump the UnityDocument to the previously loaded file location(overwrite). If file_path argument is provided, dump the document to the specified location instead.
This method keeps line endings of the original file when it dumps.
Property: Return the list of documents found in the YAML. The objects in the list are of types Class named after the serialized Unity class(ie. MonoBehaviour, GameObject, Prefab, CustomName, etc).
Property: Return the first document in the YAML, useful if there is only one. Equivalent of doing UnityDocument.entries[0]
.
Method: Return a single entry uniquely matching the given filters. Must exist exactly one.
Method: Return a list of entries matching the given filters. Many or none can be matched.
PyYAML's Loader class, can be used directly with PyYAML to customise loading.
PyYAML's Dumper class, can be used directly with PyYAML to customise dumping.
Text scalars which are single or double quoted that span multiple lines are not being dumped exactly as Unity does. There's a difference in the maximum length allowed per line and the logic to wrap them.
FAQs
A python library to parse and dump Unity YAML files
We found that unityparser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Libxml2’s solo maintainer drops embargoed security fixes, highlighting the burden on unpaid volunteers who keep critical open source software secure.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.