Commit Graph

8411 Commits

Author SHA1 Message Date
SpecificProtagonist
d0caea0882
Relationship(…Target) html trait tag (#18140)
# Objective

Fixes #18117

These are component subtraits, but unlike for `Event` (before that bound
got removed) this still shows it as a component because it's actually
used as such.

## Testing

```sh
 RUSTDOCFLAGS="--html-after-content docs-rs/trait-tags.html --cfg docsrs_dep" RUSTFLAGS="--cfg docsrs_dep" cargo doc --no-deps --package bevy_ecs
```

---

## Showcase

![Screenshot from 2025-03-03
17-31-24](https://github.com/user-attachments/assets/4b152b3f-f9c3-4ee6-a3d4-ad10f09040b6)
2025-03-04 08:05:16 +00:00
Dmytro Banin
7a1972ed3d
One-to-One Relationships (#18087)
# Objective

Minimal implementation of directed one-to-one relationships via
implementing `RelationshipSourceCollection` for `Entity`.

Now you can do

```rust
#[derive(Component)]
#[relationship(relationship_target = Below)]
pub struct Above(Entity);

#[derive(Component)]
#[relationship_target(relationship = Above)]
pub struct Below(Entity);
```

## Future Work

It would be nice if the relationships could be fully symmetrical in the
future - in the example above, since `Above` is the source of truth you
can't add `Below` to an entity and have `Above` added automatically.

## Testing

Wrote unit tests for new relationship sources and and verified
adding/removing relationships maintains connection as expected.
2025-03-04 07:57:35 +00:00
Joshua Holmes
df6e136ab0
Replace some !Send resources with thread_local! (#17730)
# Objective

Work for issue #17682 

What's in this PR:
* Removal of some `!Send` resources that Bevy uses internally
* Replaces `!Send` resources with `thread_local!` static

What this PR does not cover:
* The ability to create `!Send` resources still exists
* Tests that test `!Send` resources are present (and should not be
removed until the ability to create `!Send` resources is removed)
* The example `log_layers_ecs` still uses a `!Send` resource. In this
example, removing the `!Send` resource results in the system that uses
it running on a thread other than the main thread, which doesn't work
with lazily initialized `thread_local!` static data. Removing this
`!Send` resource will need to be deferred until the System API is
extended to support configuring which thread the System runs on. Once an
issue for this work is created, it will be mentioned in #17667

Once the System API is extended to allow control of which thread the
System runs on, the rest of the `!Send` resources can be removed in a
different PR.
2025-03-04 07:48:02 +00:00
Shaye Garg
0b5302d96a
Replace Ambient Lights with Environment Map Lights (#17482)
# Objective

Transparently uses simple `EnvironmentMapLight`s to mimic
`AmbientLight`s. Implements the first part of #17468, but I can
implement hemispherical lights in this PR too if needed.

## Solution

- A function `EnvironmentMapLight::solid_color(&mut Assets<Image>,
Color)` is provided to make an environment light with a solid color.
- A new system is added to `SimulationLightSystems` that maps
`AmbientLight`s on views or the world to a corresponding
`EnvironmentMapLight`.

I have never worked with (or on) Bevy before, so nitpicky comments on
how I did things are appreciated :).

## Testing

Testing was done on a modified version of the `3d/lighting` example,
where I removed all lights except the ambient light. I have not included
the example, but can if required.

## Migration
`bevy_pbr::AmbientLight` has been deprecated, so all usages of it should
be replaced by a `bevy_pbr::EnvironmentMapLight` created with
`EnvironmentMapLight::solid_color` placed on the camera. There is no
alternative to ambient lights as resources.
2025-03-04 07:40:53 +00:00
Ben Frankel
0a841ba9c1
Cache systems by S instead of S::System (#16694)
# Objective

- Fixes the issue described in this comment:
https://github.com/bevyengine/bevy/issues/16680#issuecomment-2522764239.

## Solution

- Cache one-shot systems by `S: IntoSystem` (which is const-asserted to
be a ZST) rather than `S::System`.

## Testing

Added a new unit test named `cached_system_into_same_system_type` to
`system_registry.rs`.

---

## Migration Guide

The `CachedSystemId` resource has been changed:

```rust
// Before:
let cached_id = CachedSystemId::<S::System>(id);
assert!(id == cached_id.0);

// After:
let cached_id = CachedSystemId::<S>::new(id);
assert!(id == SystemId::from_entity(cached_id.entity));
```
2025-03-04 07:31:10 +00:00
Martín Maita
f3db44b635
Update ureq requirement from 2.10.1 to 3.0.8 (#18146)
# Objective

- Closes #18131

## Solution

- Update ureq requirement from 2.10.1 to 3.0.8 and migrate breaking
code.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-04 01:11:28 +00:00
Martín Maita
a23f397dab
Update ruzstd requirement from 0.7.0 to 0.8.0 (#18145)
# Objective

- Fixes #18129

## Solution

- Update ruzstd requirement from 0.7.0 to 0.8.0 and fixed imports.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-03 21:44:51 +00:00
ickshonpe
912de69cfb
Val::resolve doc comment fix (#18143)
# Objective

Fix the doc comment for `Val::resolve`. It doesn't return a value in
logical pixels unless the inputs are also in logical pixels.
2025-03-03 19:49:52 +00:00
dependabot[bot]
cf18c346d8
Update itertools requirement from 0.13 to 0.14 (#18128)
Updates the requirements on
[itertools](https://github.com/rust-itertools/itertools) to permit the
latest version.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md">itertools's
changelog</a>.</em></p>
<blockquote>
<h2>0.14.0</h2>
<h3>Breaking</h3>
<ul>
<li>Increased MSRV to 1.63.0 (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/960">#960</a>)</li>
<li>Removed generic parameter from <code>cons_tuples</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/988">#988</a>)</li>
</ul>
<h3>Added</h3>
<ul>
<li>Added <code>array_combinations</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/991">#991</a>)</li>
<li>Added <code>k_smallest_relaxed</code> and variants (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/925">#925</a>)</li>
<li>Added <code>next_array</code> and <code>collect_array</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/560">#560</a>)</li>
<li>Implemented <code>DoubleEndedIterator</code> for
<code>FilterOk</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/948">#948</a>)</li>
<li>Implemented <code>DoubleEndedIterator</code> for
<code>FilterMapOk</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/950">#950</a>)</li>
</ul>
<h3>Changed</h3>
<ul>
<li>Allow <code>Q: ?Sized</code> in <code>Itertools::contains</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/971">#971</a>)</li>
<li>Improved hygiene of <code>chain!</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/943">#943</a>)</li>
<li>Improved <code>into_group_map_by</code> documentation (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/1000">#1000</a>)</li>
<li>Improved <code>tree_reduce</code> documentation (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/955">#955</a>)</li>
<li>Improved discoverability of <code>merge_join_by</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/966">#966</a>)</li>
<li>Improved discoverability of <code>take_while_inclusive</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/972">#972</a>)</li>
<li>Improved documentation of <code>find_or_last</code> and
<code>find_or_first</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/984">#984</a>)</li>
<li>Prevented exponentially large type sizes in
<code>tuple_combinations</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/945">#945</a>)</li>
<li>Added <code>track_caller</code> attr for <code>asser_equal</code>
(<a
href="https://redirect.github.com/rust-itertools/itertools/issues/976">#976</a>)</li>
</ul>
<h3>Notable Internal Changes</h3>
<ul>
<li>Fixed clippy lints (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/956">#956</a>,
<a
href="https://redirect.github.com/rust-itertools/itertools/issues/987">#987</a>,
<a
href="https://redirect.github.com/rust-itertools/itertools/issues/1008">#1008</a>)</li>
<li>Addressed warnings within doctests (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/964">#964</a>)</li>
<li>CI: Run most tests with miri (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/961">#961</a>)</li>
<li>CI: Speed up &quot;cargo-semver-checks&quot; action (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/938">#938</a>)</li>
<li>Changed an instance of <code>default_features</code> in
<code>Cargo.toml</code> to <code>default-features</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/985">#985</a>)</li>
</ul>
<h2>0.13.0</h2>
<h3>Breaking</h3>
<ul>
<li>Removed implementation of <code>DoubleEndedIterator</code> for
<code>ConsTuples</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/853">#853</a>)</li>
<li>Made <code>MultiProduct</code> fused and fixed on an empty iterator
(<a
href="https://redirect.github.com/rust-itertools/itertools/issues/835">#835</a>,
<a
href="https://redirect.github.com/rust-itertools/itertools/issues/834">#834</a>)</li>
<li>Changed <code>iproduct!</code> to return tuples for maxi one
iterator too (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/870">#870</a>)</li>
<li>Changed <code>PutBack::put_back</code> to return the old value (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/880">#880</a>)</li>
<li>Removed deprecated <code>repeat_call, Itertools::{foreach, step,
map_results, fold_results}</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/878">#878</a>)</li>
<li>Removed <code>TakeWhileInclusive::new</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/912">#912</a>)</li>
</ul>
<h3>Added</h3>
<ul>
<li>Added <code>Itertools::{smallest_by, smallest_by_key, largest,
largest_by, largest_by_key}</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/654">#654</a>,
<a
href="https://redirect.github.com/rust-itertools/itertools/issues/885">#885</a>)</li>
<li>Added <code>Itertools::tail</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/899">#899</a>)</li>
<li>Implemented <code>DoubleEndedIterator</code> for
<code>ProcessResults</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/910">#910</a>)</li>
<li>Implemented <code>Debug</code> for <code>FormatWith</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/931">#931</a>)</li>
<li>Added <code>Itertools::get</code> (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/891">#891</a>)</li>
</ul>
<h3>Changed</h3>
<ul>
<li>Deprecated <code>Itertools::group_by</code> (renamed
<code>chunk_by</code>) (<a
href="https://redirect.github.com/rust-itertools/itertools/issues/866">#866</a>,
<a
href="https://redirect.github.com/rust-itertools/itertools/issues/879">#879</a>)</li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="a015a68315"><code>a015a68</code></a>
Add <code>next_array</code> and <code>collect_array</code></li>
<li><a
href="a1213e1c81"><code>a1213e1</code></a>
Prepare v0.14.0 release</li>
<li><a
href="ff0c942b2e"><code>ff0c942</code></a>
fix clippy lints</li>
<li><a
href="f80883b8e0"><code>f80883b</code></a>
Fix into_group_map_by documentation errors</li>
<li><a
href="b793238ff1"><code>b793238</code></a>
Add track_caller for asser_equal</li>
<li><a
href="5d4056b643"><code>5d4056b</code></a>
<code>default_features</code> is deprecated - switch it to
<code>default-features</code></li>
<li><a
href="a447b68960"><code>a447b68</code></a>
doc for added trait</li>
<li><a
href="d0479b0807"><code>d0479b0</code></a>
&quot;nitpicks&quot;</li>
<li><a
href="35c78ce0bc"><code>35c78ce</code></a>
IndexMut -&gt; BorrowMut&lt;slice&gt;</li>
<li><a
href="deb53ba210"><code>deb53ba</code></a>
refactored to share code</li>
<li>Additional commits viewable in <a
href="https://github.com/rust-itertools/itertools/compare/v0.13.0...v0.14.0">compare
view</a></li>
</ul>
</details>
<br />


Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-03-03 19:36:29 +00:00
Tim Overbeek
173680944f
fix generics for relationships (#18136)
# Objective
Allow Relationship to be derived for structs with generics.

fixes #18133
## Solution

"X" inside #[relationship_target(relationship = X)] was previously
parsed as Idents,
now they are parsed as syn::Type

## Testing

```rust
#[derive(Component)]
#[relationship(relationship_target = Attachments<T>)]
pub struct AttachedTo<T: Send + Sync + 'static> {
    #[relationship]
    pub entity: Entity,
    pub marker: PhantomData<T>,
}

#[derive(Component)]
#[relationship_target(relationship = AttachedTo<T>)]
pub struct Attachments<T: Send + Sync + 'static> {
    #[relationship]
    entities: Vec<Entity>,
    pub marker: PhantomData<T>,
}
```
This now compiles!
2025-03-03 19:33:29 +00:00
Patrick Walton
236091adce
Reextract meshes when their material assets change. (#18123)
This commit makes the
`mark_meshes_as_changed_if_their_materials_changed` system use the new
`AssetChanged<MeshMaterial3d>` query filter in addition to
`Changed<MeshMaterial3d>`. This ensures that we update the
`MeshInputUniform`, which contains the bindless material slot. Updating
the `MeshInputUniform` fixes problems that occurred when the
`MeshBindGroupAllocator` reallocated meshes in such a way as to change
their bindless slot.

Closes #18102.
2025-03-03 06:28:33 +00:00
Nathan Fenner
755adae0f8
fix test for .iter().sort() to include data to sort (#18127)
The test case `query_iter_sorts` was doing lots of comparisons to ensure
that various query arrays were sorted, but the arrays were all empty.

This PR spawns some entities so that the entity lists to compare not
empty, and sorting can actually be tested for correctness.
2025-03-03 06:24:43 +00:00
Greeble
f42ecc44f8
Fix panic with multiple fog volumes (#18119)
# Objective

Fixes https://github.com/bevyengine/bevy/issues/17590.

## Solution

`prepare_volumetric_fog_uniforms` adds a uniform for each combination of
fog volume and view. But it only allocated enough uniforms for one fog
volume per view.

## Testing

Ran the `volumetric_fog` example with 1/2/3/4 fog volumes. Also checked
the `fog_volumes` and `scrolling_fog` examples (without multiple
volumes). Win10/Vulkan/Nvidia.

To test multiple views I tried adding fog volumes to the `split_screen`
example. This doesn't quite work - the fog should be centred on the fox,
but instead it's centred on the window. Same result with and without the
PR, so I'm assuming it's a separate bug.


![image](https://github.com/user-attachments/assets/4a74d6d7-8a73-4322-9dc6-c5ddd054ece2)
2025-03-03 06:22:36 +00:00
Rob Parrett
bfdd018d21
Fix webgl2 feature gating affecting webgpu in transmission example (#18115)
# Objective

Fixes #18095

## Solution

Update the feature gates so that `Taa`, etc are added if
- Not on wasm
- OR using webgpu

## Testing

Check that `Taa` is disabled with appropriate messaging on webgl2
```
cargo run -p build-wasm-example -- --api webgl2 transmission && basic-http-server examples/wasm/
```

Check that `Taa` works on webgpu in chrome
```
cargo run -p build-wasm-example -- --api webgpu transmission && basic-http-server examples/wasm/
```

Check that `Taa` still works in a native build
```
cargo run -example transmission
```
2025-03-02 22:56:34 +00:00
Alice Cecile
3be01c4d0f
Fix label name for Deliberate-Rendering-Change CI (#18118)
# Objective

The label added in #18064 is the wrong color! It should be an `M-`
(meta) label, not an `S-` (status) label!

## Solution

- Rename the label in the comment that gets left to
`M-Deliberate-Rendering-Change`
- Also make the job check for the right label 🤦🏽‍♀️ 

Once this is approved and ready to merge, I'll rename the label on
Github to match.
2025-03-02 22:54:54 +00:00
Alice Cecile
2ad5908e58
Make Query::single (and friends) return a Result (#18082)
# Objective

As discussed in #14275, Bevy is currently too prone to panic, and makes
the easy / beginner-friendly way to do a large number of operations just
to panic on failure.

This is seriously frustrating in library code, but also slows down
development, as many of the `Query::single` panics can actually safely
be an early return (these panics are often due to a small ordering issue
or a change in game state.

More critically, in most "finished" products, panics are unacceptable:
any unexpected failures should be handled elsewhere. That's where the
new

With the advent of good system error handling, we can now remove this.

Note: I was instrumental in a) introducing this idea in the first place
and b) pushing to make the panicking variant the default. The
introduction of both `let else` statements in Rust and the fancy system
error handling work in 0.16 have changed my mind on the right balance
here.

## Solution

1. Make `Query::single` and `Query::single_mut` (and other random
related methods) return a `Result`.
2. Handle all of Bevy's internal usage of these APIs.
3. Deprecate `Query::get_single` and friends, since we've moved their
functionality to the nice names.
4. Add detailed advice on how to best handle these errors.

Generally I like the diff here, although `get_single().unwrap()` in
tests is a bit of a downgrade.

## Testing

I've done a global search for `.single` to track down any missed
deprecated usages.

As to whether or not all the migrations were successful, that's what CI
is for :)

## Future work

~~Rename `Query::get_single` and friends to `Query::single`!~~

~~I've opted not to do this in this PR, and smear it across two releases
in order to ease the migration. Successive deprecations are much easier
to manage than the semantics and types shifting under your feet.~~

Cart has convinced me to change my mind on this; see
https://github.com/bevyengine/bevy/pull/18082#discussion_r1974536085.

## Migration guide

`Query::single`, `Query::single_mut` and their `QueryState` equivalents
now return a `Result`. Generally, you'll want to:

1. Use Bevy 0.16's system error handling to return a `Result` using the
`?` operator.
2. Use a `let else Ok(data)` block to early return if it's an expected
failure.
3. Use `unwrap()` or `Ok` destructuring inside of tests.

The old `Query::get_single` (etc) methods which did this have been
deprecated.
2025-03-02 19:51:56 +00:00
Kim Simmons
ff1ae62e1c
Fix incorrect doc about GamepadAxis::RightZ/LeftZ (#18114)
# Objective

Documentation correction.

# Reasoning
The `GamepadAxis::RightZ` and `LeftZ` do not map to the trigger buttons
on a gamepad. They are in fact for the twisting/yaw of a flight Joystick
and throttle lever respectively. I confirmed this with two gamepads that
has analog triggers (Logitech F710, 8bitdo ultimate BT controller) and a
HOTAS joystick (Saitek X52).
2025-03-02 19:18:01 +00:00
Rob Parrett
36cb64b382
Bump typos to 1.30.0 (#18097)
# Objective

Update `typos` and fix newly detected typos.


[Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md#1300---2025-03-01)
(just a dictionary update releases)

## Solution

Fix em

- Describe the solution used to achieve the objective above.

## Testing

CI
2025-03-02 19:02:23 +00:00
Joshua Maleszewski
1ef334cc25
Make asset watcher work when path contains "../" (#18023)
# Objective

Fixes #18022

## Solution

Canonicalize asset paths

## Testing

I ran the examples `sprite`, `desk_toy` and `game_menu` with the feature
`file_watcher` enabled. All correctly updated an asset when the source
file was altered.

Co-authored-by: Threadzless <threadzless@gmail.com>
2025-03-02 18:15:27 +00:00
aloucks
ef9b898c2d
Fix invisible window creation on Windows (#18105)
# Objective

Fixes #18027 

## Solution

Run `redraw_requested` logic in `about_to_wait` on Windows during
initial application startup and when in headless mode

## Testing

- Ran `cargo run --example window_settings` to demonstrate invisible
window creation worked again and fixes #18027
- Ran `cargo run --example eased_motion` to demonstrate no regression
with the fix for #17488

Ran all additional `window` examples. 

Notes:

- The `transparent_window` was not transparent but this appears to have
been broken prior to #18004. See: #7544
2025-03-02 18:07:21 +00:00
Patrick Walton
57143a8298
Add missing bindless imports in pbr_prepass.wgsl. (#18110)
The bindless reform PR neglected to include these, causing the prepass
shader to fail to compile in some circumstances.
2025-03-02 09:12:18 +00:00
RobWalt
73ffd9a508
chore: update compile fail test stderr files (#18056)
I noticed this while working on #18017 . Some of the `stderr`
compile_fail tests were updated while I generated the output for the new
tests I introduced in the mentioned PR.

I'm on rust 1.85.0
2025-03-01 00:31:55 +00:00
Zachary Harrold
fdd9ffab01
Allow bevy_reflect and wgpu-types features in no_std for bevy_color (#18061)
# Objective

- Improve feature parity in `no_std` for `bevy_color`

## Solution

- Allowed `bevy_reflect` in `no_std` now that it has full support
- Allowed `wgpu-types` in `no_std` now version 24 has full support
- Added `critical-section` feature to make standalone usage in `no_std`
easier

## Testing

- `cargo check -p bevy_color --no-default-features --features
libm,bevy_reflect,critical-section,serialize,alloc,wgpu-types --target
thumbv6m-none-eabi`

---

## Notes

With these changes, `bevy_color`'s feature support looks like this:

| Feature | `no_std` (Before) | `no_std` (After) | Notes |
| - | - | - | - |
| `default` |  |  | |
| `std` |  |  | |
| `alloc` | ✔️ | ✔️ | |
| `serialize` | ✔️ | ✔️ | |
| `bevy_reflect` |  | ✔️ | |
| `wgpu-types` |  | ✔️ | |
| `encase` |  |  | |
| `libm` | ✔️ | ✔️ | |
| `critical-section` |  | ✔️ | |
2025-03-01 00:31:35 +00:00
JaySpruce
ad1691e44a
Update EntityCommands::trigger to check for the entity's existence (#18071)
## Objective

`EntityCommands::trigger` internally uses `Commands::trigger_targets`,
which means it gets queued using `Commands::queue` rather
`EntityCommands::queue`. This previously wouldn't have made much
difference, but now entity commands check whether the entity exists, and
that check never happens in this case.

## Solution

- Add `entity_command::trigger`, which calls the same function as before
(`World::trigger_targets_with_caller`) but through the `EntityWorldMut`
passed to entity commands.
- Change `EntityCommands::trigger` to queue the new entity command
normally.
2025-03-01 00:08:03 +00:00
Greeble
780f658f2c
Update ChildOf deprecation advice to match new layout (#18089)
https://github.com/bevyengine/bevy/pull/17905 replaced `ChildOf(entity)`
with `ChildOf { parent: entity }`, but some deprecation advice was
overlooked. Also corrected formatting in documentation.

## Testing

Added a `set_parent` to a random example. Confirmed that the deprecation
warning shows and the advice can be pasted in.
2025-02-28 23:15:23 +00:00
Will Schroeder
e43b28c1ec
moved Debug from derive to impl_ptr in bevy_ptr (#18042)
# Objective

Fixes #17988

## Solution

Added two Debug impls to the `impl_ptr` macro - one for Aligned and one
for Unaligned.

## Testing

No tests have been added. Would a test guaranteeing debug layout be
appropriate?

---

## Showcase

The debug representation of a `Ptr<'_, Aligned>` follows. `PtrMut` and
`OwningPtr` are similar.

`Ptr<Aligned>(0x0123456789ab)`
2025-02-28 02:54:46 +00:00
Carter Anderson
b73811d40e
Remove ChildOf::get and Deref impl (#18080)
# Objective

There are currently three ways to access the parent stored on a ChildOf
relationship:

1. `child_of.parent` (field accessor)
2. `child_of.get()` (get function)
3. `**child_of` (Deref impl)

I will assert that we should only have one (the field accessor), and
that the existence of the other implementations causes confusion and
legibility issues. The deref approach is heinous, and `child_of.get()`
is significantly less clear than `child_of.parent`.

## Solution

Remove `impl Deref for ChildOf` and `ChildOf::get`.

The one "downside" I'm seeing is that:

```rust
entity.get::<ChildOf>().map(ChildOf::get)
```
Becomes this:

```rust
entity.get::<ChildOf>().map(|c| c.parent)
```

I strongly believe that this is worth the increased clarity and
consistency. I'm also not really a huge fan of the "pass function
pointer to map" syntax. I think most people don't think this way about
maps. They think in terms of a function that takes the item in the
Option and returns the result of some action on it.

## Migration Guide

```rust
// Before
**child_of
// After
child_of.parent

// Before
child_of.get()
// After
child_of.parent

// Before
entity.get::<ChildOf>().map(ChildOf::get)
// After
entity.get::<ChildOf>().map(|c| c.parent)
```
2025-02-27 23:11:03 +00:00
François Mockers
0122b85cc3
comment on PR when example job finds changes (#18064)
# Objective

- Comment on PR when getting a rendering change

## Solution

- When something changes in the rendering check CI, add a comment on the
PR to check the results
- Suggest adding the label `S-Deliberate-Rendering-Change` if it's
expected
- Don't comment if the label is already present

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-02-27 22:46:10 +00:00
JaySpruce
058497e0bb
Change Commands::get_entity to return Result and remove panic from Commands::entity (#18043)
## Objective

Alternative to #18001.

- Now that systems can handle the `?` operator, `get_entity` returning
`Result` would be more useful than `Option`.
- With `get_entity` being more flexible, combined with entity commands
now checking the entity's existence automatically, the panic in `entity`
isn't really necessary.

## Solution

- Changed `Commands::get_entity` to return `Result<EntityCommands,
EntityDoesNotExistError>`.
- Removed panic from `Commands::entity`.
2025-02-27 21:05:16 +00:00
Tim Overbeek
ccb7069e7f
Change ChildOf to Childof { parent: Entity} and support deriving Relationship and RelationshipTarget with named structs (#17905)
# Objective

fixes #17896 

## Solution

Change ChildOf ( Entity ) to ChildOf { parent: Entity }

by doing this we also allow users to use named structs for relationship
derives, When you have more than 1 field in a struct with named fields
the macro will look for a field with the attribute #[relationship] and
all of the other fields should implement the Default trait. Unnamed
fields are still supported.

When u have a unnamed struct with more than one field the macro will
fail.
Do we want to support something like this ? 

```rust
 #[derive(Component)]
 #[relationship_target(relationship = ChildOf)]
 pub struct Children (#[relationship] Entity, u8);
```
I could add this, it but doesn't seem nice.
## Testing

crates/bevy_ecs - cargo test


## Showcase


```rust

use bevy_ecs::component::Component;
use bevy_ecs::entity::Entity;

 #[derive(Component)]
 #[relationship(relationship_target = Children)]
 pub struct ChildOf {
     #[relationship]
     pub parent: Entity,
     internal: u8,
 };

 #[derive(Component)]
 #[relationship_target(relationship = ChildOf)]
 pub struct Children {
     children: Vec<Entity>
 };

```

---------

Co-authored-by: Tim Overbeek <oorbecktim@Tims-MacBook-Pro.local>
Co-authored-by: Tim Overbeek <oorbecktim@c-001-001-042.client.nl.eduvpn.org>
Co-authored-by: Tim Overbeek <oorbecktim@c-001-001-059.client.nl.eduvpn.org>
Co-authored-by: Tim Overbeek <oorbecktim@c-001-001-054.client.nl.eduvpn.org>
Co-authored-by: Tim Overbeek <oorbecktim@c-001-001-027.client.nl.eduvpn.org>
2025-02-27 19:22:17 +00:00
JaySpruce
67146bdef7
Add missing unsafe to entity_command::insert_by_id and make it more configurable (#18052)
## Objective

`insert_by_id` is unsafe, but I forgot to add that to the
manually-queueable version in `entity_command`.

It also can only insert using `InsertMode::Replace`, when it could
easily be configurable by threading an `InsertMode` parameter to the
final `BundleInserter::insert` call.

## Solution

- Add `unsafe` and safety comment.
- Add `InsertMode` parameter to `entity_command::insert_by_id`,
`EntityWorldMut::insert_by_id_with_caller`, and
`EntityWorldMut::insert_dynamic_bundle`.
- Add `InsertMode` parameter to `entity_command::insert` and remove
`entity_command::insert_if_new`, for consistency with the other
manually-queued insertion commands.
2025-02-27 06:20:32 +00:00
Zachary Harrold
ad016cb850
Improve bevy_reflect no_std support (#18060)
# Objective

- Fixes #18051

## Solution

- Switched function registry to use `bevy_platform_support::sync`
instead of `std::sync`
- Also documented that `debug_stack` (and transitively `debug`) require
`std`
- Also removed `std` from `wgpu-types` since that crate is now `no_std`
compatible

## Testing

- `cargo check -p bevy_reflect --no-default-features --features
critical-section,documentation,glam,glam/libm,smallvec,wgpu-types,functions
--target thumbv6m-none-eabi`

---

## Notes

With these changes, `bevy_reflect`'s feature support looks like this:

| Feature | `no_std` (Before) | `no_std` (After) | Notes |
| - | - | - | - |
| `default` |  |  | |
| `std` |  |  | |
| `documentation` | ✔️ | ✔️ | |
| `functions` |  | ✔️ | |
| `critical-section` | ✔️ | ✔️ | |
| `bevy` | ✔️* | ✔️* | Partial due to `smol_str` |
| `debug` |  |  | |
| `debug_stack` |  |  | |
| `petgraph` |  |  | |
| `glam` | ✔️* | ✔️* | Requires enabling `glam/libm` |
| `smallvec` | ✔️ | ✔️ | |
| `uuid` | ✔️* | ✔️* | Requires setting up `getrandom` backend |
| `wgpu-types ` |  | ✔️ | |
| `smol_str` | ✔️* | ✔️* | Partial due to `smol_str` not supporting
`portable-atomic` |
2025-02-27 06:16:10 +00:00
urben1680
2f384643c3
Bubble sync points if ignore_deferred, do not ignore if target system is exclusive (#17880)
# Objective

Fixes #17828

This fixes two bugs:

1. Exclusive systems should see the effect of all commands queued to
that point. That does not happen when the system is configured with
`*_ignore_deferred` which may lead to surprising situations. These
configurations should not behave like that.
2. If `*_ignore_deferred` is used, no sync point may be added at all
**after** the config. Currently this can happen if the last nodes in
that config have no deferred parameters themselves. Instead, sync points
should always be added after such a config, so long systems have
deferred parameters.

## Solution

1. When adding sync points on edges, do not consider
`AutoInsertApplyDeferredPass::no_sync_edges` if the target is an
exclusive system.
2. when going through the nodes in a directed way, store the information
that `AutoInsertApplyDeferredPass::no_sync_edges` suppressed adding a
sync point at the target node. Then, when the target node is evaluated
later by the iteration and that prior suppression was the case, the
target node will behave like it has deferred parameters even if the
system itself does not.

## Testing

I added a test for each bug, please let me know if more are wanted and
if yes, which cases you would want to see.
These tests also can be read as examples how the current code would
fail.
2025-02-26 20:39:23 +00:00
Ruslan Baynazarov
c7531074bc
Improve cubic segment bezier functionality (#17645)
# Objective

- Fixes #17642

## Solution

- Implemented method `new_bezier(points: [P; 4]) -> Self` for
`CubicSegment<P>`
- Old implementation of `new_bezier` is now `new_bezier_easing(p1: impl
Into<Vec2>, p2: impl Into<Vec2>) -> Self` (**breaking change**)
- ~~added method `new_bezier_with_anchor`, which can make a bezier curve
between two points with one control anchor~~
- added methods `iter_positions`, `iter_velocities`,
`iter_accelerations`, the same as in `CubicCurve` (**copied code,
potentially can be reduced)**
- bezier creation logic is moved from `CubicCurve` to `CubicSegment`,
removing the unneeded allocation

## Testing

- Did you test these changes? If so, how?
  - Run tests inside `crates/bevy_math/`
  - Tested the functionality in my project
- Are there any parts that need more testing?
  - Did not run `cargo test` on the whole bevy directory because of OOM
- Performance improvements are expected when creating `CubicCurve` with
`new_bezier` and `new_bezier_easing`, but not tested
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
  - Use in any code that works created `CubicCurve::new_bezier`
- If relevant, what platforms did you test these changes on, and are
there any important ones you can't test?
  - I don't think relevant

---

## Showcase

```rust
// Imagine a car goes towards a local target

// Create a simple `CubicSegment`, without using heap
let planned_path = CubicSegment::new_bezier([
    car_pos,
    car_pos + car_dir * turn_radius,
    target_point - target_dir * turn_radius,
    target_point,
]);

// Check if the planned path itersect other entities
for pos in planned_path.iter_positions(8) {
   // do some collision checks
}
```

## Migration Guide

> This section is optional. If there are no breaking changes, you can
delete this section.

- Replace `CubicCurve::new_bezier` with `CubicCurve::new_bezier_easing`
2025-02-26 20:36:54 +00:00
Chris Russell
94e6fa168f
Fix unsoundness in QueryIter::sort_by (#17826)
# Objective

`QueryIter::sort_by()` is unsound. It passes the lens items with the
full `'w` lifetime, and a malicious user could smuggle them out of the
closure where they could alias with the query results.

## Solution

Make the sort closures generic in the lifetime parameter of the lens
item. This ensures the lens items cannot outlive the call to the
closure.

## Testing

Added a compile-fail test that demonstrates the unsound pattern.

## Migration Guide

The `sort` family of methods on `QueryIter` unsoundly gave access
`L::Item<'w>` with the full `'w` lifetime. It has been shortened to
`L::Item<'w>` so that items cannot escape the comparer. If you get
lifetime errors using these methods, you will need to make the comparer
generic in the new lifetime. Often this can be done by replacing named
`'w` with `'_`, or by replacing the use of a function item with a
closure.

```rust
// Before: Now fails with "error: implementation of `FnMut` is not general enough"
query.iter().sort_by::<&C>(Ord::cmp);
// After: Wrap in a closure
query.iter().sort_by::<&C>(|l, r| Ord::cmp(l, r));

query.iter().sort_by::<&C>(comparer);
// Before: Uses specific `'w` lifetime from some outer scope
// now fails with "error: implementation of `FnMut` is not general enough"
fn comparer(left: &&'w C, right: &&'w C) -> Ordering { /* ... */ }
// After: Accepts any lifetime using inferred lifetime parameter
fn comparer(left: &&C, right: &&C) -> Ordering { /* ... */ }
2025-02-26 20:36:37 +00:00
François Mockers
23cf8ffe6c
update CI patch for EventWriter::send deprecation (#18044)
# Objective

- EventWriter::send has been deprecated, but it was used by one of the
CI patch

## Solution

- Use EventWriter::write instead
2025-02-26 20:36:15 +00:00
Matty Weatherley
4b1745f813
BRP resource methods (#17423)
# Objective

So far, built-in BRP methods allow users to interact with entities'
components, but global resources have remained beyond its reach. The
goal of this PR is to take the first steps in rectifying this shortfall.

## Solution

Added five new default methods to BRP:
- `bevy/get_resource`: Extracts the value of a given resource from the
world.
- `bevy/insert_resource`: Serializes an input value to a given resource
type and inserts it into the world.
- `bevy/remove_resource`: Removes the given resource from the world.
- `bevy/mutate_resource`: Replaces the value of a field in a given
resource with the result of serializing a given input value.
- `bevy/list_resources`: Lists all resources in the type registry with
an available `ReflectResource`.

## Testing

Added a test resource to the `server` example scene that you can use to
mess around with the new BRP methods.

## Showcase

Resources can now be retrieved and manipulated remotely using a handful
of new BRP methods. For example, a resource that looks like this:
```rust
#[derive(Resource, Reflect, Serialize, Deserialize)]
#[reflect(Resource, Serialize, Deserialize)]
pub struct PlayerSpawnSettings {
  pub location: Vec2,
  pub lives: u8,
}
```

can be manipulated remotely as follows.

Retrieving the value of the resource:
```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "bevy/get_resource",
  "params": {
    "resource": "path::to::my::module::PlayerSpawnSettings"
  }
}
```

Inserting a resource value into the world:
```json
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "bevy/insert_resource",
  "params": {
    "resource": "path::to::my::module::PlayerSpawnSettings",
    "value": {
      "location": [
        2.5, 
        2.5
      ],
      "lives": 25
    }
  }
}
```

Removing the resource from the world:
```json
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "bevy/remove_resource",
  "params": {
    "resource": "path::to::my::module::PlayerSpawnSettings"
  }
}
```

Mutating a field of the resource specified by a path:
```json
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "bevy/mutate_resource",
  "params": {
    "resource": "path::to::my::module::PlayerSpawnSettings",
    "path": ".location.x",
    "value": -3.0
  }
}
```

Listing all manipulable resources in the type registry:
```json
{
  "jsonrpc": "2.0",
  "id": 5,
  "method": "bevy/list_resources"
}
```
2025-02-26 20:29:47 +00:00
Lucas Franca
11db71727d
Refactor bevy_gltf (#15994)
# Objective

Refactor `bevy_gltf`, the criteria for the split is kind of arbitrary
but at least it is not a 2.6k line file.

## Solution

Move methods and structs found in `bevy_gltf/loader.rs` into multiple
new modules.

## Testing

`cargo run -p ci`
2025-02-26 01:00:11 +00:00
Aevyrie
831ecf030c
TaskPool: Prefer task completion over executing new tasks (#18009)
# Objective

- Systems that use the task pool, either explicitly or implicitly using
parallel queries, will often end up executing tasks from different
systems.
- This can cause random tasks to block the main or render schedule at
random, adding frame variance and increasing frame times when CPU bound.
- This profile is a common occurrence on `main`.
`propagate_parent_transforms` takes more than twice as long as it
should, blocking the main schedule for that time, because it uses `task
pool.scope`, which has decided to execute tasks from the render schedule
on the main schedule.

![image](https://github.com/user-attachments/assets/c363be40-82ce-451e-ba29-3eb4ee367e0b)


## Solution

- In task pool scope execution, prefer to check if the current task is
complete instead of ticking the executor to find new work.

## Testing

- Ran the scene viewer with tracy to look for images like the one in the
objective section.
- Things look much, much better, and I could not find any occurrences: 

![image](https://github.com/user-attachments/assets/18b79394-1a7c-49c1-820a-f5207e81bbac)

![image](https://github.com/user-attachments/assets/e7d4831d-66c3-41c1-ae2c-a624724c9965)
2025-02-26 00:08:36 +00:00
Sou1gh0st
f2b37c733e
Deduplicate register_inherited_required_components (#16519)
# Objective
- Fixes #16416 

## Solution
- Add a intermediate temporary mutable `RequiredComponents` to get avoid
of the borrowing issues.

## Testing

- I have run `cargo test --package bevy_ecs -- --exact --show-output`
and past all the tests.
2025-02-25 23:59:58 +00:00
Martín Maita
05bad0673f
Removes compile_fail glob pattern (#18040)
# Objective

- Attempts to fix #17876.

## Solution

- Reverted some changes that added a glob pattern to match all
`compile_fail` crates. This should enable Dependabot to create PRs
again.
- Added a TODO comment to not forget that this glob matching failure
should also be fixed in the Dependabot repo.
2025-02-25 23:53:17 +00:00
SpecificProtagonist
25cee420e4
do_not_recommend interned Labels (#17950)
# Objective

Follow up on #17441 now that `do_not_recommend` is stable.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-02-25 23:46:21 +00:00
JaySpruce
36a2f7fdf1
Remove unnecessary bounds on EntityClonerBuilder::without_required_components (#17969)
## Objective

The closure argument for
`EntityClonerBuilder::without_required_components` has `Send + Sync +
'static` bounds, but the closure immediately gets called and never needs
to be sent anywhere. (This was my fault :P )

## Solution

Remove the bounds so that users aren't unnecessarily restricted.

I also took the opportunity to expand the tests a little.
2025-02-25 23:34:46 +00:00
François Mockers
2f633c18ba
Split example runs to their own GitHub workflow (#18039)
# Objective

- next step for #15918 

## Solution

- Move jobs for macOS, Linux and Windows to their own workflow
- Remove running on push to `main` from workflows CI and validation
2025-02-25 23:30:31 +00:00
Tristan Maindron
0f153ffb44
Prevent last_trigger_id from overflowing (#17978)
# Objective

This prevents overflowing the `last_trigger_id` property that leads to a
panic in debug mode.

```bash
panicked at C:\XXX\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_ecs-0.15.2\src\world\unsafe_world_cell.rs:630:18:
attempt to add with overflow
Encountered a panic when applying buffers for system `bevy_sprite::calculate_bounds_2d`!
Encountered a panic in system `bevy_ecs::schedule::executor::apply_deferred`!
```

## Solution

As this value is only used for detecting a change, we can wrap when it
reaches max value.

## Testing

This can be verified by running `cargo run --example observers`
2025-02-25 23:12:51 +00:00
Brezak
b43c8f8c4f
Add methods to add single entity relationships (#18038)
# Objective

Closes #17572

## Solution

Add the `add_one_related` methods to `EntityCommands` and
`EntityWorldMut`.

## Testing

Clippy

---

## Showcase

The `EntityWorldMut` and `FilteredResourcesMut` now include the
`add_one_related` method if you just want to relate 2 entities.
2025-02-25 23:07:44 +00:00
Brezak
5961df7c89
Automatically close weekly ci issue if weekly ci succeeds (#18016)
# Objective

It's not always obvious when the issue created by the weekly CI run is
safe to close.

## Solution

Automatically close it when a weekly CI run succeeds so it doesn't get
forgotten.

## Testing

Hope.
2025-02-25 19:21:04 +00:00
Patrick Walton
df5e3a7b96
Load each glTF skin at most once. (#18026)
Currently, we reload a glTF skin each time we encounter a node that
references it. By checking for duplicates, PR #18013 turned this into a
fatal error. But this was always wasteful. This commit fixes the issue
by caching each skin by its index as we load it.

The Maya babylon.js export plugin likes to emit glTFs with multiple
nodes that reference the same skin, so this effectively unbreaks Maya
rigs.
2025-02-25 01:27:29 +00:00
Zachary Harrold
20813aed64
Handle TriggerTargets that are combinations for components/entities (#18024)
# Objective

* Fixes https://github.com/bevyengine/bevy/issues/14074
* Applies CI fixes for #16326

It is currently not possible to issues a trigger that targets a specific
list of components AND a specific list of entities

## Solution

We can now use `((A, B), (entity_1, entity_2))` as a trigger target, as
well as the reverse

## Testing

Added a unit test.

The triggering rules for observers are quite confusing:

Triggers once per entity target

For each entity target, an observer system triggers if any of its
components matches the trigger target components (but it triggers at
most once, since we use an internal counter to make sure that an
observer can run at most once per entity target)

(copied from #14563)
(copied from #16326)

## Notes

All credit to @BenjaminBrienen and @cBournhonesque! Just applying a
small fix to this PR so it can be merged.

---------

Co-authored-by: Benjamin Brienen <Benjamin.Brienen@outlook.com>
Co-authored-by: Christian Hughes <xdotdash@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-02-24 23:57:34 +00:00
andriyDev
ed1143b26b
Make adding a subasset label return a result for if there is a duplicate label. (#18013)
# Objective

- Makes #18010 more easily debuggable. This doesn't solve that issue,
but protects us from it in the future.

## Solution

- Make `LoadContext::add_labeled_asset` and friends return an error if
it finds a duplicate asset.

## Testing

- Added a test - it fails before the fix.

---

## Migration Guide

- `AssetLoader`s must now handle the case of a duplicate subasset label
when using `LoadContext::add_labeled_asset` and its variants. If you
know your subasset labels are unique by construction (e.g., they include
an index number), you can simply unwrap this result.
2025-02-24 21:51:40 +00:00