Skip to content

Add lint: lifecycle observer is invalid for disabled entities #524

@janhohenheim

Description

@janhohenheim

What problem does this solve or what need does it fill?

The example is written with Add, but similar things like Remove are affected the same way.

fn on_add(trigger: On<Add, Foo>, query: Query<&Foo>) {
  // panics when spawning `(Foo, Disabled)`
  let foo = query.get(trigger.target()).unwrap();
  // fails to uphold invariants of the observer when `Disabled` is removed
  let Ok(foo) = query.get(trigger.target()) else { return; };
}

What solution would you like?

fn on_add(trigger: On<Add, Foo>, query: Query<&Foo, Allow<Disabled>>) {
  // works
  let foo = query.get(trigger.target()).unwrap();
}

What alternative(s) have you considered?

Wait until reactivity is merged. There's a Com and ComMut proposal for getting the components of the triggered entity. That could presumably implicitly allow disabled internally

Additional context

Plugin code not respecting this will break downstream users' ability to use disabled entities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LinterRelated to the linter and custom lintsC-FeatureMake something new possible

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions