bevyengine / bevyengine/bevy

Early return on run condition evaluation.

Open
#10,046 5 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Feature S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?
If you have nested run conditions then "inner" or "lower level" will be evaluated even if "outermost" or "higher level" results to false.

This leads to wasting of resources and useless evaluation of run condition even if they don't need to be.

(I am not sure how to describe it but code snippet lower demonstrates actual vs desired behaviour)

## What solution would you like?

If run condition in "higher" hierarchy resolves to false, then return early.

## What alternative(s) have you considered?

Intended behaviour ?

## Additional context

Let's have this bevy app:

```rust
use bevy::prelude::*;

fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_systems(
Update,
(
(
system_a.run_if(move || {
println!("inner condition");
true
}),
system_b,
)
.run_if(move || {
println!("outer condition");
false
}),
end,
)
.chain(),
)
.run();
}

fn system_a() {
println!("system_a system");
}

fn system_b() {
println!("system_b system");
}

fn end() {
println!("end system")
}
```

This will print:
```
outer condition
inner condition
end system
```

Ideally this should only print:
```
outer condition
end system
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.