-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Replace HierarchyEvent
with OnParentChange
trigger
#13925
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
Changes from 4 commits
810f584
3f6cbab
90152d7
a9b4f3c
41cdaab
6a8aff0
fb99eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,19 @@ | ||
use bevy_ecs::{event::Event, prelude::Entity}; | ||
|
||
/// An [`Event`] that is fired whenever there is a change in the world's hierarchy. | ||
/// A [`Trigger`] emitted whenever there is a change in the world's hierarchy. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see more clarity in these docs about which entity is triggered. I believe it's the A doc test would also be nice here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the long wait! I tried to clarify this a bit now. It's actually triggered for the child entity that has the If the event was instead triggered for parents, it would need to be triggered for both the old and new parent for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also added a simple doc example. Not sure if it should use Couldn't make it into an actual doc test nicely, since the observer makes it a bit awkward to test things. I did test it manually though, and the actual tests should cover it. |
||
/// | ||
/// [`Event`]: bevy_ecs::event::Event | ||
#[derive(Event, Debug, Clone, PartialEq, Eq)] | ||
pub enum HierarchyEvent { | ||
/// Fired whenever an [`Entity`] is added as a child to a parent. | ||
ChildAdded { | ||
/// The child that was added | ||
child: Entity, | ||
/// The parent the child was added to | ||
parent: Entity, | ||
}, | ||
/// Fired whenever a child [`Entity`] is removed from its parent. | ||
ChildRemoved { | ||
/// The child that was removed | ||
child: Entity, | ||
/// The parent the child was removed from | ||
parent: Entity, | ||
}, | ||
/// Fired whenever a child [`Entity`] is moved to a new parent. | ||
ChildMoved { | ||
/// The child that was moved | ||
child: Entity, | ||
/// The parent the child was removed from | ||
previous_parent: Entity, | ||
/// The parent the child was added to | ||
new_parent: Entity, | ||
/// [`Trigger`]: bevy_ecs::observer::Trigger | ||
#[derive(Event, Clone, Debug, PartialEq)] | ||
pub enum OnParentChange { | ||
/// Emitted whenever the entity is added as a child to a parent. | ||
Added(Entity), | ||
/// Emitted whenever the child entity is removed from its parent. | ||
Removed(Entity), | ||
/// Emitted whenever the child entity is moved to a new parent. | ||
Moved { | ||
/// The parent the child was removed from. | ||
previous: Entity, | ||
/// The parent the child was added to. | ||
new: Entity, | ||
}, | ||
} |
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.
This is an example of somewhere the observer will be called much sooner that an
EventReader<HierarchyEvent>
could have responded. It will see theEntity
just as it has been spawned, before any components could be added. Open Question: Is this desirable?