Repository navigation
Animation root observer for Tween events - #98
Just-Helpful wants to merge 34 commits into
Conversation
This lets us listen to said events on the entity that we inserted the animation on i.e. we can use: ``` commands .animation(...) .observe(...) ```
|
Thanks for making this PR. Although I think we might be having this struct doing too much by default. Originally it's just doing a single thing, which was I believe user should be able to choose between the following:
We could have this as an option inside current TweenEvent, or split all of them into different struct and their data component counterparts, or something in between. I'm not entirely sure what's the best practical choice here but the crate has always been "composition-first", have a single component do a single work then we compose them together, so maybe we should do the separated struct design. If we're going with the separated struct design, I propose the names:
|
|
I'd be up for that. I assume the |
|
My only concern would be with the combinators that trigger those |
|
I think it would also still be useful to include a generic |
|
I'll make the changes and just let me know if there's anything blindingly wrong I guess. |
|
Names could be |
+ removes hard requirement on emitter marker allowing us to use different markers with `TweenEventData`
These event combinators are now all technically `self_` event combinators, so I've named them as such
Between tween events and tween messages. There might still be a little confusion as the same `TweenEvent` struct is used for both... Not quite sure what to do about this one.
These better match the functionality they are now demonstrating and actually match the combinator names used within the examples
|
Okay, after implementing this a bit: It's difficult to avoid bevy pinging global event listeners when we fire an entity event (not unless we want to pick apart bevy's internals and hand roll the Whilst I've left an implementation for |
|
In this implementation we could also maybe (?) make the generic |
Yeah, let's just do that then. Since the global observer could be ran multiple times, stated in the original problem, we should add like I don't think we should have |
The way these combinators send events is a difficult to observe with entity events, so I'm discarding them in favor of `root` event combinators
Also cleans up some left over references to `self_event`s
This makes it a little easier to understand how dispatch works and also allows for potentially naughty stuff like attaching an dispatch marker and an observer component at the same time.
|
Okay, that change has been made. |
Co-authored-by: Multirious <77918086+Multirious@users.noreply.github.com>
Fundamentally all that matters about this query data *is* that it can produce a `TweenEvent` for a given entity, not *how* it does that.
|
Okay, those have both been updated. The only real bit I'm unsure about is logging a |
I think it's fine. I can't imagine where other place TweenEvent can be composed in, given the constraint we declared on the component. And user can always just not register this system. |
Objective
Whilst
TweenEvents areEntityEvents, they do not propagate to the animation root.This makes it difficult to register entity observers on animated entities.
Solution
Adds automatic propagation to an entities animation root
as defined by the bevy
TimeRunnerused to drive animation.Warning
This change does result in firing a global observer more than once (often twice).
Whilst this is a breaking change, it is possible to filter these events by
event.entity.It's up to you whether you're okay with this...
Testing
I added an entity observer on the existing
entity_event.rsexampleand confirmed that the corresponding entity observer was fired.
I also performed a visual comparison of the existing
event.rsand confirmed minimal visual changes.Showcase
Enabled behaviour:
commands .animation(...) .observe(|event: On<TweenEvent<&'static str>>| { println!("TweenEvent fired for this animation {:?}", event.data) })No change seen in the
event.rsexample:https://github.com/user-attachments/assets/35880219-5ff8-4858-be57-f7862856f2cf
https://github.com/user-attachments/assets/0ab2982b-3805-47d6-9e96-0d9369ac0440
Updates made to
entity_event.rs:commands .animation() .insert(sequence(( forward(Duration::from_secs_f32(3.)), event("tween"), forward(Duration::from_secs_f32(0.5)), event("event"), ))) // + entity observer added .observe(|trigger: On<TweenEvent<&'static str>>| { println!("TweenEvent on root: {}", trigger.data) });Screencast.From.2026-10-23.21-16-38.mp4
To-Do Checklist