Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
[FEATURE MODIFICATION] Prefab system compatible with atelier-assets #1894
Atelier-assets is almost at feature parity now. I think prefabs is the only missing existing feature, and naturally it has a bunch of other new shiny features that are not available in the current asset system.
I would like to introduce a design for a new prefab system that is inspired by Unity's latest iteration of prefabs. My idea is to implement this as an experimental feature in Amethyst that uses atelier-assets while keeping the existing prefab system as it is, perhaps the current one in the future.
From a user perspective, a prefab is a container of entities that can be instantiated in the ECS world. Translating this into the asset system, a prefab is an asset that references a set of other assets that each define an entity with its set of components.
The file format would look something like this, inspired by randomPoison's
Authoring a prefab
Ideally we create a tool for creating prefabs since it's really annoying to deal with UUIDs, overrides etc in the file. I don't expect anyone to author these files by hand.
I think taking inspiration from Unity's UX will be good here.
"Cooking" a prefab
Resolving all these references, value overrides etc can get pretty expensive and complicated at runtime. To simplify loading and instantiation code, we should "cook" the prefab down to a simple collection of entities + components without overrides by copying all referenced entities into the prefab, apply all overrides etc. This can happen in the atelier-daemon in the build stage so that the runtime code can be kept simple.
Loading & instantiating a prefab
Loading a cooked prefab should be pretty simple as it becomes a single asset with a format that can be optimized for loading & instantiating. Handwaving a bit here, should dive deeper into how this format should look later.
Overrides is the key to making prefabs powerful, but is also the most complicated part in the system. There are two parts to making this work.
We need to be able to address a field within a Component and serialize/deserialize only a set of fields. Rukai's treeflection already sort of does this. It uses Strings a bit more than I'd like, but maybe it can work out.
When authoring a prefab, we will most likely need to figure out which values of an instance of a prefab differ from the prefab template to be able to extract a set of override path/value pairs. We may be able to fork/modify
I want to implement a more powerful and easy-to-use prefab system that integrates well with the new asset system. This will make Amethyst scene authoring and management much nicer and enable some really cool tooling.
I think this can be implemented without impacting existing code, making it a backwards compatible change.