bevy_scene: Add ReflectBundle#6344
Conversation
b9ec315 to
4029144
Compare
|
First: I do think we need something functionally similar to this! Being able to specify a "logical group" of entity configuration and only specify components with non-default values is an important step for the scene system / this has always been the plan. However this is controversial as its starting to encroach on "prefab space" and the concerns outlined in the "Components as Bundles" conversation: #2974 (comment), where we agreed that Bundles should just be "simple groups of components" (at least for now). The main question is: Will we support Bundles in scene editing scenarios? Supporting 3 concepts seems like too many:
Will Bundles "become" prefabs? Is this even technically feasible? (this would require a number of internal changes to bevy_ecs / break existing assumptions). Does that mean components are also prefabs? |
Makes sense, I don't have an issue with marking this as controversial.
Yeah there are a lot of vaguely similar concepts that are liable to confuse users. Each one kinda blends into the next (especially when coming from something like Unity or another engine). I don't think bundles should be prefabs, but they definitely can be viewed that way. They encapsulate a set of components, can define data for those components (think constructors or So in my eyes, and I'm sure others, bundles are prefab-like. The main differences1 are that they don't provide any other prefab-related functionality and they don't really "exist" in the world (as they're just sugar for a group of components2). And the same could be said for components (they're basically just a bundle with one item). All that to say, I think we could go ahead with My arguments for it:
My arguments against it:
Footnotes |
4029144 to
203cf79
Compare
|
@MrGVSV maybe we can have |
# Objective Similar to #6344, but contains only `ReflectBundle` changes. Useful for scripting. The implementation has also been updated to look exactly like `ReflectComponent`. --- ## Changelog ### Added - Reflection for bundles. --------- Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
# Objective Similar to bevyengine#6344, but contains only `ReflectBundle` changes. Useful for scripting. The implementation has also been updated to look exactly like `ReflectComponent`. --- ## Changelog ### Added - Reflection for bundles. --------- Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
# Objective Similar to bevyengine#6344, but contains only `ReflectBundle` changes. Useful for scripting. The implementation has also been updated to look exactly like `ReflectComponent`. --- ## Changelog ### Added - Reflection for bundles. --------- Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
|
Backlog cleanup: closing due to inactivity, and because it seems like once |
Objective
Scenes do not currently support spawning entire bundles. This means that in order to simulate spawning a bundle, one must include all components within that bundle.
Given the following bundle:
We must then include the following in our scene file:
[ { "entity": 0, "components": [ { "my_crate::ComponentA": { "foo": "Hello World" } }, { "my_crate::ComponentB": {} }, { "my_crate::ComponentC": {} }, { "my_crate::ComponentD": {} }, { "my_crate::ComponentE": {} }, { "my_crate::ComponentF": {} }, { "my_crate::ComponentG": {} } ] } ]We only needed to specify data for
ComponentA. All other components in the bundle could have just as easily been left out since we didn't have to specify anything for them (or perhaps they're just markers).Solution
Add
ReflectBundleto allow scenes to spawn complete bundles.With this change, we can now update our example bundle:
And add a
bundlessection to our scene files:[ { "entity": 0, "components": [] "bundles": { "a": { "foo": "Hello World" } } } ]Much nicer!
Considerations
There are some caveats to this system we might need to consider:
bundlesfield will never be serialized by theDynamicSceneserializer. This could be confusing to users who expect it to serialize. The problem is, we don't have a great way of knowing whether every necessary component exists to create a valid bundle and not lose any information. So for now it's a manually-written/deserialize-only feature.Components also implementBundle, it would be possible to register aReflectBundlefor a component. If this is done, then applying the "bundle" will result in each field of the component being inserted onto the entity. This is obviously not good. However, there's not a good way of knowing whether aBundleis only a component or not. If we could add aBundle::IS_COMPONENTconstant or something, it might be possible to throw an error when attempting to create aReflectBundlefor a component.Changelog
ReflectBundlebundlesfield toDynamicEntitybundlesmap to be optionally included per entity in scene files