Skip to content
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

Add resource hooks (and observers) #12231

Open
alice-i-cecile opened this issue Mar 1, 2024 · 4 comments
Open

Add resource hooks (and observers) #12231

alice-i-cecile opened this issue Mar 1, 2024 · 4 comments
Assignees
Labels
A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible X-Controversial There is active debate or serious implications around merging this PR
Milestone

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

Hooks, which give users the ability to respond to components being added and removed (in #10756) are really neat: reasonably performant, atomic, hard to mess up.

I'd like to be able to use this for resources as well: see #11426 for an in-engine design where I think this might help simplify the design and make things more robust.

What solution would you like?

Mirror the work in #10756 and #10839 for resources, condensing internal structure to avoid duplication as needed.

What alternative(s) have you considered?

Don't bother implementing this: the truly complex cases (hierarchies, indexes, relations) that motivate hooks and observers for components are less applicable for resources.

Additional context

I'm not 100% sure we should add this, and am very happy to wait and see if there's a real need or desire for this. But users will ask, and I wanted to open a central place for discussion on design/need/implementation.

@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 Mar 1, 2024
@MiniaczQ
Copy link
Contributor

MiniaczQ commented Mar 1, 2024

There is a lack of change detection for Resources, since you cannot change-query for them, observers would nicely fill that gap.

Another interesting target for events are assets, emitting events, especially for "done loading" could be useful and fill in the gap for post-load asset processing.

@alice-i-cecile
Copy link
Member Author

FYI, change detection for resources does exist: you just have to call .is_changed or .is_added on Res / ResMut :)

I agree that this is particularly useful for assets.

@orbachl-mcmaster
Copy link

orbachl-mcmaster commented Mar 4, 2024

I think there is value here - as you mentioned states could be made simpler with something like this.

But there is a flip-side that is significant - since a hook is generally expected to occur immediately* after the trigger, you could fairly easily end up with infinite loops and the like.

For stuff like hierarchies/relations/indexes that tradeoff might be useful - but we'd have to decide if our current resource uses are applicable as well.

Edit: Accidentally commented while in a work account! This is @lee-orr

@MiniaczQ
Copy link
Contributor

MiniaczQ commented Mar 4, 2024

you could fairly easily end up with infinite loops and the like.

Yup, #12240 is intended to help debug infinite loops

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 X-Controversial There is active debate or serious implications around merging this PR
Projects
None yet
Development

No branches or pull requests

3 participants