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

Run observers before hooks for on_replace and on_remove #16499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nakedible
Copy link
Contributor

Objective

Solution

  • Trivially swaps ordering of hooks and observers for all call sites where they are triggered for on_replace or on_remove

Testing

  • Just CI

Migration Guide

The order of hooks and observers for on_replace and on_remove has been swapped. Observers are now run before hooks. This is a more natural ordering where the removal ordering is inverted compared to the insertion ordering.

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me conceptually. Nice work!

@nakedible nakedible marked this pull request as ready for review November 25, 2024 00:59
@nakedible
Copy link
Contributor Author

The fix pull runs now hooks after observers, but observers are run in the same order as on insertion, not in reverse order. Flecs says observer ordering is undefined, and I also think that having undefined ordering is better than saying observers are called in insertion order (or reverse insertion order). So I believe it's fine that the observers are not run in reverse order by this pull.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 25, 2024
@nakedible
Copy link
Contributor Author

If guaranteed observer ordering is added (in a separate pull), then that pull should also add functionality to call the observers in reverse order, and this reverse order should be used for OnReplace and OnRemove observers.

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-Bug An unexpected or incorrect behavior M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hook and observer ordering for on_remove/on_replace should be inverted
4 participants