-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ComponentStorage and associated types #12311
Remove ComponentStorage and associated types #12311
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Does this mean that we can store Box<dyn Component>
without specifying an associated storage type finally? That would be really cool if so.
I don't think so. Actually I think that was the reason why it's still that way. Associated consts make the type not object safe. However, do we want to support Component trait objects? I don't think we can do anything with it, not even downcast. |
Yeah, it's fundamentally not object safe. I'd still maybe like an object-safe subtrait for Bundle at some point for a "if X, insert bundle A, otherwise bundle B" but I don't think that's vital (and this change is orthogonal to it). |
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
# Objective When doing a final pass for bevyengine#3362, it appeared that `ComponentStorage` as a trait, the two types implementing it, and the associated type on `Component` aren't really necessary anymore. This likely was due to an earlier constraint on the use of consts in traits, but that definitely doesn't seem to be a problem in Rust 1.76. ## Solution Remove them. --- ## Changelog Changed: `Component::Storage` has been replaced with `Component::STORAGE_TYPE` as a const. Removed: `bevy::ecs::component::ComponentStorage` trait Removed: `bevy::ecs::component::TableStorage` struct Removed: `bevy::ecs::component::SparseSetStorage` struct ## Migration Guide If you were manually implementing `Component` instead of using the derive macro, replace the associated `Storage` associated type with the `STORAGE_TYPE` const: ```rust // in Bevy 0.13 impl Component for MyComponent { type Storage = TableStorage; } // in Bevy 0.14 impl Component for MyComponent { const STORAGE_TYPE: StorageType = StorageType::Table; } ``` Component is no longer object safe. If you were relying on `&dyn Component`, `Box<dyn Component>`, etc. please [file an issue ](https://github.com/bevyengine/bevy/issues) to get [this change](bevyengine#12311) reverted. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Addresses Bevy [12311](bevyengine/bevy#12311)
I was relying on Box through the following methods:
Is there an alternative to this now? I was using this type to selectively save some of my objects. My use case is very unique; I am making a text-based MUD game. So the normal saving methods that exist in the Bevy community are not appliable to me. I had to develop my own methods for it! Any help appreciated so that I can migrate to 0.14. |
Do scenes work for you? I don't see any particular reason why the typical reflection-based approach wouldn't be applicable in a text-based game. Anyways, maybe make a Discussion so this can be seen more broadly? |
We have a system which saves it to SQL, I believe that the one that is used saves it to a file? Is there any documentation I can review on the matter? I've been using the ECS more than other parts, so I am not so familiar. |
|
Objective
When doing a final pass for #3362, it appeared that
ComponentStorage
as a trait, the two types implementing it, and the associated type onComponent
aren't really necessary anymore. This likely was due to an earlier constraint on the use of consts in traits, but that definitely doesn't seem to be a problem in Rust 1.76.Solution
Remove them.
Changelog
Changed:
Component::Storage
has been replaced withComponent::STORAGE_TYPE
as a const.Removed:
bevy::ecs::component::ComponentStorage
traitRemoved:
bevy::ecs::component::TableStorage
structRemoved:
bevy::ecs::component::SparseSetStorage
structMigration Guide
If you were manually implementing
Component
instead of using the derive macro, replace the associatedStorage
associated type with theSTORAGE_TYPE
const:Component is no longer object safe. If you were relying on
&dyn Component
,Box<dyn Component>
, etc. please file an issue to get this change reverted.