-
-
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
Entity Markers #6556
Comments
This requires enum variants as types, which is not possible in Rust. See: |
But it works for SystemLabel, and it is infact just a label. the whole entity it corresponds to wouldn't be stored in the marker directly but would be in a lookup table, wouldn't it? |
This specific part would not work: |
oh! thats pretty sad. But with structs it would work? like #[derive(Marker)]
pub struct RedPlayer; ? |
You can basically achieve something to the same effect by just using individual "marker components": #[derive(Component)]
pub struct Red;
#[derive(Component)]
pub struct Blue; commands.spawn((Player::new(), Red)); fn system(query: Query<Player, With<Red>>) {
// ...
} |
Yes but that doesn't have to only resolve into one entity. it can have multiple when you don't do it quite well.. but thats probably a better thing than using a resource |
If you need it to resolve it into one entity, why not store that entity in a resource? Like #[derive(Resource)]
pub struct RedPlayer(Entity);
#[derive(Resource)]
pub struct BluePlayer(Entity); So that you can guarantee you can have one entity for each color. |
If you need a singleton but don't want to use a Resource, there is also the |
yeah but both of them are a little bit messy or don't really guarantee that you'll have one. And both of them make it hard for the scheduler to asynchronously handle them because the information that we only want that one specific entity won't be given to the scheduler (at least thats what i thought) |
While that's true in some senses.. a system that only mutably queries for a single entity is unlikely to run for a very long period of time. Plus if you had such a large number of systems in your schedule that you were worried about wasting any CPU time at all.. surely many of those other systems would not need access to the same components and so could run concurrently anyway? |
Well.. thats true.. it's just a feature request because i think its a neat feature i would also like. when you say its not worth it then ok :). but ideas are always good, aren't they? |
certainly :) |
Yep, unless and until we get something like enum-variants-as-types, this can't be implemented. Closing this out :) |
Ok I'm happy to pronounce: I made a working thing for this in 3 hours 🤣. Was very fun to make: https://github.com/ChoppedStudio/bevy_ecs_markers |
Super cool! What's the algorithmic complexity of this approach? |
To get from the marker to the |
|
:O nice to hear 😁 |
Yesterday I made some performance and style improvements, it now feels like it would be a normal bevy feature 😂 |
Because of |
What problem does this solve or what need does it fill?
A Marker trait that can mark an entity. example
then we can assign an entity with a marker
and we can easily query players
What solution would you like?
An Marker that works like a Resource but holds a EntityID and the Marker can be used in Queries.
What alternative(s) have you considered?
Manually make Resources holding EntityIDs and then using a normal query and using .get with the entityID from the resource.
The text was updated successfully, but these errors were encountered: