bevy/crates/bevy_ecs/src/world
urben1680 1294b71e35
Introduce CheckChangeTicks event that is triggered by World::check_change_ticks (#19274)
# Objective

In the past I had custom data structures containing `Tick`s. I learned
that these need to be regularly checked to clamp them. But there was no
way to hook into that logic so I abandoned storing ticks since then.

Another motivation to open this up some more is to be more able to do a
correct implementation of `System::check_ticks`.

## Solution

Add `CheckChangeTicks` and trigger it in `World::check_change_ticks`.
Make `Tick::check_tick` public.

This event makes it possible to store ticks in components or resources
and have them checked.

I also made `Schedules::check_change_ticks` public so users can store
schedules in custom resources/components for whatever reasons.

## Testing

The logic boils down to a single `World::trigger` call and I don't think
this needs more tests.

## Alternatives

Making this obsolete like with #15683.

---

## Showcase

From the added docs:

```rs
use bevy_ecs::prelude::*;
use bevy_ecs::component::CheckChangeTicks;

#[derive(Resource)]
struct CustomSchedule(Schedule);

let mut world = World::new();
world.add_observer(|tick: Trigger<CheckChangeTicks>, mut schedule: ResMut<CustomSchedule>| {
    schedule.0.check_change_ticks(tick.get());
});
```

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-06-09 20:44:49 +00:00
..
command_queue.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
component_constants.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
deferred_world.rs Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
entity_fetch.rs Fix regression on the get/get_mut/get_not_found (#19505) 2025-06-06 21:04:27 +00:00
entity_ref.rs Remove entity placeholder from observers (#19440) 2025-06-09 19:37:56 +00:00
error.rs FilteredResource returns a Result instead of a simple Option (#18265) 2025-03-17 18:54:13 +00:00
filtered_resource.rs Only get valid component ids (#19510) 2025-06-06 20:59:57 +00:00
identifier.rs Rename bevy_platform_support to bevy_platform (#18813) 2025-04-11 23:13:28 +00:00
mod.rs Introduce CheckChangeTicks event that is triggered by World::check_change_ticks (#19274) 2025-06-09 20:44:49 +00:00
reflect.rs Only get valid component ids (#19510) 2025-06-06 20:59:57 +00:00
spawn_batch.rs Encapsulate cfg(feature = "track_location") in a type. (#17602) 2025-02-10 21:21:20 +00:00
unsafe_world_cell.rs Only get valid component ids (#19510) 2025-06-06 20:59:57 +00:00