Skip to content

How can I 'ask' an Entity about its information prettier? #20176

Answered by GglLfr
Lineoo asked this question in Q&A
Discussion options

You must be logged in to vote

For this kind of logic I usually do this, which basically boils down to using World::trigger_targets_ref:

#[derive(Event)]
struct Ready {
    flag: bool,
}

let mut entity: EntityWorldMut = /* ... */;
let id = entity.id();

// Something listening to `Ready` can set `Trigger::event_mut().flag = false`.
let mut ready = Ready { flag: true };
entity.world_scope(|world| world.trigger_targets_ref(&mut ready, id));

if ready.flag {
    entity.trigger(Attack);
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Lineoo
Comment options

Answer selected by Lineoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants