Skip to content

Conversation

@patrickariel
Copy link
Contributor

Adds observer triggers on top of normal events so that users can now use observers to listen to tween events (this is similar to the approach used upstream).

This adds a new Clone constraint to tween_event_taking_system, because the event now needs to be moved to both the observer and the event writer.

@Multirious
Copy link
Owner

Multirious commented Nov 26, 2024

Thanks for the PR! Now I'm not sure if adding the Clone constraint is to taking-event appropriate. It's originally made for events that do not implemented Clone. Though I have no idea how common that usages is. We may need to do more researches regarding this but if you have any opinions please do tell!

@patrickariel
Copy link
Contributor Author

I personally don't use it, so I'm not really sure if there are any legitimate use-cases for it. Another downside is that EntityEvent requires Clone, which means that non-clone events can't benefit from it. Maybe it could be removed?

@Multirious
Copy link
Owner

We probably could probably remove the entire thing entirely so TweenEvent wouldn't need to always have Option inside them.

@patrickariel
Copy link
Contributor Author

Ok, removed the event taking system and the Option<Data> thing!

@Multirious Multirious mentioned this pull request Dec 3, 2024
9 tasks
@Multirious Multirious merged commit 67f63c0 into Multirious:main Dec 8, 2024
3 checks passed
@rendaoer
Copy link

In fact, the trigger object here is not reasonable. Using animation() to add animation will create a sub-entity. The entity of the trigger here is the sub-entity, but it is difficult to obtain the id of this sub-entity when you listen.

@Multirious
Copy link
Owner

Multirious commented Jul 27, 2025

@rendaoer One way to solve this is via a custom event function/combinator.

pub fn my_event<Data>( event_data: Data, entity_id: &mut Option<Entity>, // Or use Entity::PLACE_HOLDER ) -> impl FnOnce(&mut AnimationCommands, &mut Duration) where Data: Send + Sync + 'static, { move |a, pos| { let entity = a.spawn(( TimeSpan::try_from(*pos..=*pos).unwrap(), TweenEventData::with_data(event_data), )); *entity_id = Some(entity.id()); } }

I have deliberately made AnimationCommands spawns entity individually instead of stuffing them all inside a custom Command (Which will result in the entity id only accessible after command flush).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants