Skip to content

Add named observers #18726

Open
Open
@tigerplush

Description

@tigerplush

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

Right now, when adding observers, they show up in the egui-inspector as Observer (1v1), Observer (2v1) etc.

Image
With a large project, this can become quite cumbersome to read and understand, so I propose adding the ability to add names to observers.

What solution would you like?

Right now, you add observers with app.add_observer(observer);, with no possiblity to specify different things.
I propose to add with_name(self, name: impl Into<String>) for IntoObserverSystem<E, B, M>, much like run_if<M>(self, condition: impl Condition<M>) has been implemented for IntoScheduleConfigs<ScheduleSystem, M>.

The final new api could look like this:
app.add_observer(observer.with_name("Custom Observer"));

What alternative(s) have you considered?

None. While it is possible, to query for Observers, it is not possible to find out where they came from once they've been spawned, so while I could add a Name component after they've been spawned, I cannot know which one.

[edit]
@notmd mentioned, you could do app.world_mut().add_observer(some_observer).insert(Name::new("Some observer"));, so for my project I'm going to write a function add_named_observer, which will be good enough for me.

Additional context

I think this has been discussed in #16384, but was closed when the inspector added a default name for Observers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedX-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    Status

    Observer overhaul

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions