mrchantey / beet

A modular behavior library for the Bevy Engine.
https://mrchantey.github.io/beet/
Apache License 2.0
45 stars 1 forks source link

Investigate Observers #4

Closed mrchantey closed 3 months ago

mrchantey commented 4 months ago

Bevy now has observers, this may be a better approach than change detection on sparse set tag components.

Option 1: Triggers for RunResult (partial adoption)

We could use trigger add/remove systems that run on some query like:

fn add_child_triggers(commands: Commands, parents: Query<&Children, Added<Running>>){
  for (parent, children) in parents.iter(){
    for child in children{
      commands.entity(parent).add_trigger::<RunResult>(child)
    }
  }
}

And i suppose something similar when it stops running..

Option 2: Triggers for RunResult and Running

Whenever children are added to a parent:

  1. the child observes the parent 'StopRunning' and also stops running as a result
  2. the parent observes the child 'StopRunning' and makes some decision or bubbles it up..
  3. the parent can trigger 'StartRunning' on the child
mrchantey commented 3 months ago

done, fully integrated

mgi388 commented 3 months ago

@mrchantey nice, is there a commit that fixes this? Can't see anything in https://github.com/mrchantey/beet/commits/main/

mrchantey commented 3 months ago

yeah sry should've closed with a pr, here it is #6