Skip to content

Named observer #18797

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Named observer #18797

wants to merge 3 commits into from

Conversation

hukasu
Copy link
Contributor

@hukasu hukasu commented Apr 10, 2025

Objective

Closes #18726

Solution

  • Add add_named_observer to App and World
  • Add observe_named to EntityCommands and EntityWorldMut

Showcase

commands.spawn_empty().observe_named(my_observer, "MyObserver");
world.entity(entity).observe_named(my_observer, "MyObserver");
world.add_named_observer(my_observer, "MyObserver");
app.add_named_observer(my_observer, "MyObserver");

TODO

  • Maybe rename add_named_observer
  • Maybe rename observe_named
  • Maybe add names to some of built-in observers

@cart
Copy link
Member

cart commented Apr 10, 2025

I would prefer to not introduce a special-cased API for this. Observers will be increasingly component driven (I might even push for deprecation of entity.observe() ). Instead, we should use commands.spawn((Observer::new(..), Name::new("My Observer")).

@hukasu
Copy link
Contributor Author

hukasu commented Apr 10, 2025

in this component driven style, the Observer would lose the entity list from the descriptor and each entity observing that observer would have the component?

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events X-Controversial There is active debate or serious implications around merging this PR labels Apr 23, 2025
@alice-i-cecile
Copy link
Member

I agree with Cart in #18726 (comment). Can you explain why you feel this should be merged as is, rather than pursuing that line?

@hukasu
Copy link
Contributor Author

hukasu commented Apr 23, 2025

This is as a draft exactly because i don't think it should be merged as-is, either it requires changes or the path that we will take is a different one, which is more likely given the talks

@alice-i-cecile alice-i-cecile added the S-Needs-Design This issue requires design work to think about how it would best be accomplished label Apr 23, 2025
@cart
Copy link
Member

cart commented Apr 23, 2025

in this component driven style, the Observer would lose the entity list from the descriptor and each entity observing that observer would have the component?

Observers would still be standalone entities, but they would define their targets via relationships (either in addition to manually defined targets on the descriptor, or instead of that). Final design is TBD but that is the general idea.

@hukasu
Copy link
Contributor Author

hukasu commented Apr 23, 2025

on the lines of Observing ObservedBy? that would require n-m relationships, right?

@alice-i-cecile
Copy link
Member

on the lines of Observing ObservedBy? that would require n-m relationships, right?

Indeed, that's why #17607 is stalled out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add named observers
3 participants