Commit Graph

8746 Commits

Author SHA1 Message Date
Frédéric Vauchelles
19682aa4c3
Added derive Reflect to UntypedHandle and UntypedAssetId (#18827)
# Objective

- We have the ability to serialize/deserialize `Handle<T>` with
[`TypedReflectSerializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectSerializer.html)
and
[`TypedReflectDeserializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectDeserializer.html),
but it is not possible for `UntypedHandle`.
- `Handle<T>` already has the `Reflect` derive, so it sounds coherent to
also have this derive also on the untyped API

## Solution

- Add the `Reflect` derive macro to both `UntypedHandle` and `
UntypedAssetId`.

## Testing

- I used a custom processor to handle the serialization based on the
example of
[`TypedReflectSerializer`](https://docs.rs/bevy/latest/bevy/reflect/serde/struct.TypedReflectSerializer.html)
(see [source
code](https://docs.rs/bevy_reflect/0.15.3/src/bevy_reflect/serde/ser/serializer.rs.html#149))

Co-authored-by: Frédéric Vauchelles <frederic.vauchelles@outlook.com>
2025-04-28 21:46:36 +00:00
mhsalem36
2556405feb
Fixes #15389, added docs to RawHandleWrapper::_window field (#18832)
# Objective

- Fixes https://github.com/bevyengine/bevy/issues/15389.
- Add documentation for RawHandleWrapper::_window field since It's
needed to drop the window at the correct time.

## Solution

- Added documentation to RawHandleWrapper::_window field as same as
WindowWrapper documentation.

## Testing

- No testing needed since it is documentation. 

---
2025-04-28 21:44:57 +00:00
JoshValjosh
7f9eae2c87
Fully qualify crate paths in BevyManifest (#18938)
# Objective

Subtle, very minor issue. The following code fails to compile on main:
```rs
struct bevy;
#[derive(::bevy::ecs::component::Component)]
struct MyComponent;
```
The derive proc macro is pasting in essentially:
```rs
impl bevy::ecs::component::Component for MyComponent
```
...which normally works, but I've added `struct bevy`, which makes the
proc macro spit out incorrect code.

Very cursed, but to my knowledge has never been encountered in practice.
All the same, it's technically incorrect and should be fixed.

## Solution

The solution is simply to prepend `::` to crate names. Specifically, all
(all?) Bevy's derive macros determine the root crate name using
`BevyManifest`, which does some toml-parsing witchcraft to figure out
whether to qualify names using the umbrella `bevy` crate or individual
`bevy_xxx` crates. I just added a `::` to the spot where we parse the
`syn::Path`. The above example compiles properly after that.

## Testing

- CI should catch any errors since this change should cause compile
errors if for some reason they're being used in a cursed way somewhere
that would make this break something.

## Note

If this does break something for someone, this *really* needs a comment
in `BevyManifest::maybe_get_path` explaining why we can't make this
change.
2025-04-28 21:43:48 +00:00
Gino Valente
31e9a3c411
bevy_reflect: Re-reflect hashbrown types (#18944)
# Objective

Fixes #18943

## Solution

Reintroduces support for `hashbrown`'s `HashMap` and `HashSet` types.
These were inadvertently removed when `bevy_platform` newtyped the
`hashbrown` types.

Since we removed our `hashbrown` dependency, I gated these impls behind
a `hashbrown` feature. Not entirely sure if this is necessary since we
enabled it for `bevy_reflect` through `bevy_platform` anyways. (Complex
features still confuse me a bit so let me know if I can just remove it!)

I also went ahead and preemptively implemented `TypePath` for `PassHash`
while I was here.

## Testing

You can test that it works by adding the following to a Bevy example
based on this PR (you'll also need to include `hashbrown` of course):

```rust
#[derive(Reflect)]
struct Foo(hashbrown::HashMap<String, String>);
```

Then check it compiles with:

```
cargo check --example hello_world --no-default-features --features=bevy_reflect/hashbrown
```
2025-04-28 19:26:53 +00:00
Krzysztof Żywiecki
7f0490655c
Removed conversion from pointer physical coordinates to viewport local coordinates in bevy_picking make_ray function (#18870)
# Objective

- Fixes #18856.

## Solution

After PR #17633, `Camera::viewport_to_world` method corrects
`viewport_position` passed in that input so that it's offset by camera's
viewport. `Camera::viewport_to_world` is used by `make_ray` function
which in turn also offsets pointer position by viewport position, which
causes picking objects to be shifted by viewport position, and it wasn't
removed in the aforementioned PR. This second offsetting in `make_ray`
was removed.

## Testing

- I tested simple_picking example by applying some horizontal offset to
camera's viewport.
- I tested my application that displayed a single rectangle with picking
on two cameras arranged in a row. When using local bevy with this fix,
both cameras can be used for picking correctly.
- I modified split_screen example: I added observer to ground plane that
changes color on hover, and removed UI as it interfered with picking
both on master and my branch. On master, only top left camera was
triggering the observer, and on my branch all cameras could change
plane's color on hover.
- I added viewport offset to mesh_picking, with my changes it works
correctly, while on master picking ray is shifted.
- Sprite picking with viewport offset doesn't work both on master and on
this branch.

These are the only scenarios I tested. I think other picking functions
that use this function should be tested but I couldn't track more uses
of it.

Co-authored-by: Krzysztof Zywiecki <krzysiu@pop-os.Dlink>
2025-04-27 13:54:28 +00:00
Martín Maita
17da7e13f2
Update spin requirement from 0.9.8 to 0.10.0 (#18655)
# Objective

- Closes #18643 

## Solution

- Updated spin requirement from 0.9.8 to 0.10.0.
- Renamed `spin/portable_atomic` feature to `spin/portable-atomic`.

## Testing

- CI checks (already passing in the dependabot PR).

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-27 06:18:24 +00:00
Mathis Brossier
119eb51f00
Fix game_of_life shader relying on Naga bug (#18951)
# Objective

The game of life example shader relies on a Naga bug
([6397](https://github.com/gfx-rs/wgpu/issues/6397) /
[4536](https://github.com/gfx-rs/wgpu/issues/4536)). In WGSL certain
arithmetic operations must be explicitly parenthesized
([reference](https://www.w3.org/TR/WGSL/#operator-precedence-associativity)).
Naga doesn't enforce that (and also the precedence order is [messed
up](https://github.com/gfx-rs/wgpu/issues/4536#issuecomment-1780113990)).

So this example may break soon. This is the only sample shader having
this issue.

## Solution

added parentheses

## Testing

ran the example before and after the fix with `cargo run --example
compute_shader_game_of_life`
2025-04-26 21:38:08 +00:00
Kristoffer Søholm
78d9f05d31
Update cosmic-text to 0.14 (#18651)
# Objective

New cosmic-text version is out, we should use it.

## Solution

Bump the version.

## Testing

Code compiles, text example works
2025-04-26 21:36:24 +00:00
Olle Lukowski
9167f02bdf
Create EntityCommands::remove_if (#18899)
# Objective

Fixes #18857.

## Solution

Add the requested method, and a `try_` variant as well.

## Testing

It compiles, doctests succeed, and is trivial enough that I don't think
it needs a unit test (correct me if I'm wrong though).
2025-04-26 21:32:02 +00:00
ickshonpe
2b7cecd5b3
FontAtlasSet fixes (#18850)
# Objective

Fix problems with  `FontAtlasSet`:

* `FontAtlasSet` derives `Asset` but `FontAtlasSet`s are not Bevy
assets.
* The doc comments state that `FontAtlasSet`s are assets that are
created automatically when fonts are loaded. They aren't, they are
created as needed during text updates.

## Solution
* Removed the `Asset` derive.
* Rewrote the doc comments.
2025-04-26 21:22:40 +00:00
Raul Rabadan Arroyo
c4408a817b
Make the example android app explicitly handle some device config change events to avoid getting the activity destroyed (#18839)
# Objective

Fixes #18316

## Solution

Add android:configChanges="orientation|screenSize" to the
AndroidManifest.xml as indicated in https://stackoverflow.com/a/3329486
to avoid the GameActivity from getting destroyed, making the app
stuck/crash.

## Testing

I checked the results in my phone and after adding the config change the
issue went away. The change is relatively trivial, so there shouldn't be
the need to make a lot more testing.
2025-04-26 21:21:50 +00:00
JoshValjosh
9cf1a1afa2
Remove unused query param (#18924)
# Objective

Was copying off `bevy_ui`'s homework writing a picking backend and
noticed the `Has<IsDefaultPickingCamera>` is not used anywhere.

## Testing

Ran a random example.

This shouldn't cause any behavioral changes at all because the
component/archetype access/filter flags should be the same. `Has<X>`
doesn't affect access since it doesn't actually read or write anything,
and it doesn't affect matched archetypes either. Can't think of another
reason any behavior would change.
2025-04-26 21:17:14 +00:00
Rahmat Nazali Salimi
26f0ce272e
Fix minor typo on bevy_ecs example (#18926)
# Objective

A small typo was found on `bevy_ecs/examples/event.rs`.
I know it's very minor but I'd think fixing it would still help others
in the long run.

## Solution

Fix the typo.

## Testing

I don't think this is necessary.
2025-04-26 21:16:09 +00:00
François Mockers
12f71a8936
don't overflow when relations are empty (#18891)
# Objective

- Fixes #18890 

## Solution

- Don't overflow when substracting, bound at 0

## Testing

- Reproducer from the issue now works
2025-04-21 20:38:43 +00:00
charlotte
18e1bf1c3d
Swap order of eviction/extraction when extracting for specialization (#18846)
# Objective

Fixes #18843 

## Solution

We need to account for the material being added and removed in the
course of the same frame. We evict the caches first because the entity
will be re-added if it was marked as needing specialization, which
avoids another check on removed components to see if it was "really"
despawned.
2025-04-15 06:44:01 +00:00
charlotte
6eaa6a6a03
Revert attempt to fix memory leak (#18845)
This reverts commit a9b0b4e7f7.
2025-04-15 01:57:53 +00:00
Carter Anderson
f3f6cad43c
Panic on overlapping one-to-one relationships (#18833)
# Objective

One to one relationships (added in
https://github.com/bevyengine/bevy/pull/18087) can currently easily be
invalidated by having two entities relate to the same target.

Alternative to #18817 (removing one-to-one relationships)

## Solution

Panic if a RelationshipTarget is already targeted. Thanks @urben1680 for
the idea!

---------

Co-authored-by: François Mockers <mockersf@gmail.com>
2025-04-15 01:25:37 +00:00
Patrick Walton
56784de769
Fix the ordering of the systems introduced in #18734. (#18825)
There's still a race resulting in blank materials whenever a material of
type A is added on the same frame that a material of type B is removed.
PR #18734 improved the situation, but ultimately didn't fix the race
because of two issues:

1. The `late_sweep_material_instances` system was never scheduled. This
PR fixes the problem by scheduling that system.

2. `early_sweep_material_instances` needs to be called after *every*
material type has been extracted, not just when the material of *that*
type has been extracted. The `chain()` added during the review process
in PR #18734 broke this logic. This PR reverts that and fixes the
ordering by introducing a new `SystemSet` that contains all material
extraction systems.

I also took the opportunity to switch a manual reference to
`AssetId::<StandardMaterial>::invalid()` to the new
`DUMMY_MESH_MATERIAL` constant for clarity.

Because this is a bug that can affect any application that switches
material types in a single frame, I think this should be uplifted to
Bevy 0.16.
2025-04-14 21:17:48 +00:00
Carter Anderson
59bdaca29d
Revert "Allow partial support for bevy_log in no_std (#18782)" (#18816)
This reverts commit ac52cca033.

Fixes #18815

# Objective

#18782 resulted in using `log` macros instead of `tracing` macros (in
the interest of providing no_std support, specifically no_atomic
support). That tradeoff isn't worth it, especially given that tracing is
likely to get no_atomic support.

## Solution

Revert #18782
2025-04-14 21:15:01 +00:00
JaySpruce
045ef4c307
Add remove_children and remove_related to EntityWorldMut and EntityCommands (#18835)
Fixes #18834.

`EntityWorldMut::remove_children` and `EntityCommands::remove_children`
were removed in the relationships overhaul (#17398) and never got
replaced.

I don't *think* this was intentional (the methods were never mentioned
in the PR or its comments), but I could've missed something.
2025-04-14 20:27:08 +00:00
Patrick Walton
5e69518f10
Don't restrict the scene viewer to loading assets from approved paths. (#18828)
The purpose of the scene viewer is to load arbitrary glTF scenes, so
it's inconvenient if they have to be moved into the Bevy assets
directory first. Thus this patch switches the scene viewer to use
`UnapprovedPathMode::Allow`.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
2025-04-14 20:19:37 +00:00
Matty Weatherley
47f46b5bdf
Expose the output curve type in with_derivative (#18826)
# Objective

I was wrong about how RPITIT works when I wrote this stuff initially,
and in order to actually give people access to all the traits
implemented by the output (e.g. Debug and so on) it's important to
expose the real output type, even if it makes the trait uglier and less
comprehensible. (☹️)

## Solution

Expose the curve output type of the `CurveWithDerivative` trait and its
double-derivative companion. I also added a bunch of trait derives to
`WithDerivative<T>`, since I think that was just an oversight.
2025-04-14 20:18:00 +00:00
JaySpruce
e3384bb8f0
Fix wrong method call in relationship replacement command (#18824)
Fixes a small mix-up from #18058, which added bulk relationship
replacement methods.

`EntityCommands::replace_related_with_difference` calls
`EntityWorldMut::replace_children_with_difference` instead of
`EntityWorldMut::replace_related_with_difference`, which means it always
operates on the `ChildOf` relationship instead of the `R: Relationship`
generic it's provided.

`EntityCommands::replace_children_with_difference` takes an `R:
Relationship` generic that it shouldn't, but it accidentally works
correctly on `main` because it calls the above method.
2025-04-14 20:15:33 +00:00
Alice Cecile
9254297acd
Use never_say_never hack to work around Rust 2024 regression for fn traits (#18804)
# Objective

After #17967, closures which always panic no longer satisfy various Bevy
traits. Principally, this affects observers, systems and commands.

While this may seem pointless (systems which always panic are kind of
useless), it is distinctly annoying when using the `todo!` macro, or
when writing tests that should panic.

Fixes #18778.

## Solution

- Add failing tests to demonstrate the problem
- Add the trick from
[`never_say_never`](https://docs.rs/never-say-never/latest/never_say_never/)
to name the `!` type on stable Rust
- Write looots of docs explaining what the heck is going on and why
we've done this terrible thing

## To do

Unfortunately I couldn't figure out how to avoid conflicting impls, and
I am out of time for today, the week and uh the week after that.
Vacation! If you feel like finishing this for me, please submit PRs to
my branch and I can review and press the button for it while I'm off.

Unless you're Cart, in which case you have write permissions to my
branch!

- [ ] fix for commands
- [ ] fix for systems
- [ ] fix for observers
- [ ] revert https://github.com/bevyengine/bevy-website/pull/2092/

## Testing

I've added a compile test for these failure cases and a few adjacent
non-failing cases (with explicit return types).

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2025-04-14 19:59:48 +00:00
lcnr
d7ec6a90f2
remove reliance on a trait solver inference bug (#18840)
The parameter `In` of `call_inner` is completely unconstrained by its
arguments and return type. We are only able to infer it by assuming that
the only associated type equal to `In::Param<'_>` is `In::Param<'_>`
itself. It could just as well be some other associated type which only
normalizes to `In::Param<'_>`. This will change with the next-generation
trait solver and was encountered by a crater run
https://github.com/rust-lang/rust/pull/133502-

cc
https://github.com/rust-lang/trait-system-refactor-initiative/issues/168

I couldn't think of a cleaner alternative here. I first tried to just
provide `In` as an explicit type parameter. This is also kinda ugly as I
need to provide a variable number of them and `${ignore(..)}` is
currently still unstable https://github.com/rust-lang/rust/issues/83527.

Sorry for the inconvenience. Also fun that this function exists to avoid
a separate solver bug in the first place 😅
2025-04-14 19:55:31 +00:00
charlotte
6f3ea06060
Make sure the mesh actually exists before we try to specialize. (#18836)
Fixes #18809
Fixes #18823

Meshes despawned in `Last` can still be in visisible entities if they
were visible as of `PostUpdate`. Sanity check that the mesh actually
exists before we specialize. We still want to unconditionally assume
that the entity is in `EntitySpecializationTicks` as its absence from
that cache would likely suggest another bug.
2025-04-14 19:09:02 +00:00
charlotte
a9b0b4e7f7
Mark render assets as modified when removed from the asset server (#18814)
# Objective

Fixes #18808

## Solution

When an asset emits a removed event, mark it as modified in the render
world to ensure any appropriate bookkeeping runs as necessary.
2025-04-11 23:18:26 +00:00
Carter Anderson
e9a0ef49f9
Rename bevy_platform_support to bevy_platform (#18813)
# Objective

The goal of `bevy_platform_support` is to provide a set of platform
agnostic APIs, alongside platform-specific functionality. This is a high
traffic crate (providing things like HashMap and Instant). Especially in
light of https://github.com/bevyengine/bevy/discussions/18799, it
deserves a friendlier / shorter name.

Given that it hasn't had a full release yet, getting this change in
before Bevy 0.16 makes sense.

## Solution

- Rename `bevy_platform_support` to `bevy_platform`.
2025-04-11 23:13:28 +00:00
François Mockers
88f863efed
don't disable std in bevy_dylib (#18807)
# Objective

- `bevy_dylib` currently doesn't build independently
```
cargo build -p bevy_dylib
   Compiling bevy_dylib v0.16.0-rc.4 (/crates/bevy_dylib)
error: no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

error: `#[panic_handler]` function required, but not found

error: unwinding panics are not supported without std
  |
  = help: using nightly cargo, use -Zbuild-std with panic="abort" to avoid unwinding
  = note: since the core library is usually precompiled with panic="unwind", rebuilding your crate with panic="abort" may not be enough to fix the problem

error: could not compile `bevy_dylib` (lib) due to 3 previous errors
```

## Solution

- remove `#![no_std]` from `bevy_dylib`

## Testing

- it builds now
2025-04-11 18:44:53 +00:00
Zachary Harrold
ac52cca033
Allow partial support for bevy_log in no_std (#18782)
# Objective

- Fixes #18781

## Solution

- Moved `LogPlugin` into its own file gated behind a new `tracing`
feature.
- Used `log` instead of `tracing` where possible.
- Exposed a new `tracing` feature in `bevy` which enables
`bevy_log/tracing`.
- Gated `LogPlugin` from `DefaultPlugins` on `tracing` feature.

## Testing

- CI

---

## Migration Guide

- If you were previously using `bevy_log` with default features
disabled, enable the new `std` and `tracing` features.
- If you were using `bevy` with the default features disabled, enable
the new `tracing` feature.

## Notes

Almost all of the diffs in this PR come from moving `LogPlugin` into its
own file. This just makes the PR less noisy, since the alternative is
excessive `#[cfg(feature = "tracing")]` directives all over the plugin.

---------

Co-authored-by: François Mockers <francois.mockers@vleue.com>
2025-04-11 01:44:38 +00:00
charlotte
24baf324d6
Allowlist mali drivers for gpu preprocessing support. (#18769)
Fixes #17591

Looking at the arm downloads page, "r48p0" is a version number that
increments, where rXX is the major version and pX seems to be a patch
version. Take the conservative approach here that we know gpu
preprocessing is working on at least version 48 and presumably higher.
The assumption here is that the driver_info string will be reported
similarly on non-pixel devices.
2025-04-11 00:03:54 +00:00
Alice Cecile
31bb878d6d
Fix system param validation for piped systems (#18785)
# Objective

- Piped systems are an edge case that we missed when reworking system
parameter validation.
- Fixes #18755.

## Solution

- Validate the parameters for both systems, ~~combining the errors if
both failed validation~~ by simply using an early out.
- ~~Also fix the same bug for combinator systems while we're here.~~

## Testing

I've added a large number of tests checking the behavior under various
permutations. These are separate tests, rather than one mega test
because a) it's easier to track down bugs that way and b) many of these
are `should_panic` tests, which will halt the evaluation of the rest of
the test!

I've also added a test for exclusive systems being pipeable because we
don't have one and I was very surprised that that works!

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
2025-04-10 23:16:22 +00:00
Carter Anderson
2944f5e79d
Ignore RenderEntity during entity clones (#18798)
# Objective

Fixes #18795

## Solution

Ignore RenderEntity during entity clones
2025-04-10 20:46:34 +00:00
Gilles Henaux
e7558cd0da
Fix documentation: incorrect references to the Update schedule in ExitCondition (#18438)
# Objective

- The referenced `ScheduleLabel` for `OnPrimaryClosed` and `OnAllClosed`
in `ExitCondition` was incorrect

## Solution

- Changed `Update` to `PostUpdate`
2025-04-10 20:31:18 +00:00
BD103
6d4a9ad01c
Make some changes to the migration guide recommendations (#18794)
# Objective

- I've worked on the migration guide in the past, so I've written down
some of the conventions and styles I've used.

## Solution

Please read through the descriptions of each commit, which justify the
change! In summary:

- Remove headings from migration guide template by moving style guide to
`migration_guides.md`
- Use parentheses to signal method and function names (`my_func()`
instead of `my_func`)
- Change the guidelines on using bullet points so they're not used for
every single migration guide.
- Remove suggestion to use diff blocks, as they don't syntax-highlight
Rust code.

---------

Co-authored-by: Rob Parrett <robparrett@gmail.com>
Co-authored-by: Miles Silberling-Cook <NthTensor@users.noreply.github.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
2025-04-10 19:25:56 +00:00
Greeble
25a8b9f9f9
Fix newline in PointLightShadowMap comment (#18791)
A clippy failure slipped into #18768, although I'm not sure why CI
didn't catch it.

```sh
> cargo clippy --version
clippy 0.1.85 (4eb161250e 2025-03-15)

> cargo run -p ci
...
error: empty line after doc comment
   --> crates\bevy_pbr\src\light\mod.rs:105:5
    |
105 | /     /// The width and height of each of the 6 faces of the cubemap.
106 | |
    | |_^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
    = note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::empty_line_after_doc_comments)]`
    = help: if the empty line is unintentional remove it
help: if the documentation should include the empty line include it in the comment
    |
106 |     ///
    |
```
2025-04-10 18:05:11 +00:00
Zachary Harrold
73f03327c2
Add ? (#18783)
# Objective

- Fixes #18780

## Solution

- Add `?`

## Testing

- CI

---

## Notes

_smol_
2025-04-10 00:27:09 +00:00
jf908
ea69012799
Small docs PR for PointLightShadowMap/DirectionalLightShadowMap (#18768)
# Objective

- Improve the docs for `PointLightShadowMap` and
`DirectionalLightShadowMap`

## Solution

- Add example for how to use `PointLightShadowMap` and move the
`DirectionalLightShadowMap` example from `DirectionalLight`.
- Match `PointLight` and `DirectionalLight` docs about shadows.
- Describe what `size` means.

---------

Co-authored-by: Robert Swain <robert.swain@gmail.com>
2025-04-09 22:23:21 +00:00
charlotte
ee7b624024
Fix forward decal depth_fade_factor. (#18772)
Fixes #18758
2025-04-09 22:00:28 +00:00
charlotte
e799625ea5
Add binned 2d/3d Wireframe render phase (#18587)
# Objective

Fixes #16896
Fixes #17737

## Solution

Adds a new render phase, including all the new cold specialization
patterns, for wireframes. There's a *lot* of regrettable duplication
here between 3d/2d.

## Testing

All the examples.

## Migration Guide
- `WireframePlugin` must now be created with
`WireframePlugin::default()`.
2025-04-09 21:34:53 +00:00
Patrick Walton
6c619397d5
Unify RenderMaterialInstances and RenderMeshMaterialIds, and fix an associated race condition. (#18734)
Currently, `RenderMaterialInstances` and `RenderMeshMaterialIds` are
very similar render-world resources: the former maps main world meshes
to typed material asset IDs, and the latter maps main world meshes to
untyped material asset IDs. This is needlessly-complex and wasteful, so
this patch unifies the two in favor of a single untyped
`RenderMaterialInstances` resource.

This patch also fixes a subtle issue that could cause mesh materials to
be incorrect if a `MeshMaterial3d<A>` was removed and replaced with a
`MeshMaterial3d<B>` material in the same frame. The problematic pattern
looks like:

1. `extract_mesh_materials<B>` runs and, seeing the
`Changed<MeshMaterial3d<B>>` condition, adds an entry mapping the mesh
to the new material to the untyped `RenderMeshMaterialIds`.

2. `extract_mesh_materials<A>` runs and, seeing that the entity is
present in `RemovedComponents<MeshMaterial3d<A>>`, removes the entry
from `RenderMeshMaterialIds`.

3. The material slot is now empty, and the mesh will show up as whatever
material happens to be in slot 0 in the material data slab.

This commit fixes the issue by splitting out `extract_mesh_materials`
into *three* phases: *extraction*, *early sweeping*, and *late
sweeping*, which run in that order:

1. The *extraction* system, which runs for each material, updates
`RenderMaterialInstances` records whenever `MeshMaterial3d` components
change, and updates a change tick so that the following system will know
not to remove it.

2. The *early sweeping* system, which runs for each material, processes
entities present in `RemovedComponents<MeshMaterial3d>` and removes each
such entity's record from `RenderMeshInstances` only if the extraction
system didn't update it this frame. This system runs after *all*
extraction systems have completed, fixing the race condition.

3. The *late sweeping* system, which runs only once regardless of the
number of materials in the scene, processes entities present in
`RemovedComponents<ViewVisibility>` and, as in the early sweeping phase,
removes each such entity's record from `RenderMeshInstances` only if the
extraction system didn't update it this frame. At the end, the late
sweeping system updates the change tick.

Because this pattern happens relatively frequently, I think this PR
should land for 0.16.
2025-04-09 21:32:10 +00:00
charlotte
f75078676b
Initialize pre-processing pipelines only when culling is enabled. (#18759)
Better fix for #18463 that still allows enabling mesh preprocessing on
webgpu.

Fixes #18463
2025-04-09 21:31:29 +00:00
Patrick Walton
065a95e0a1
Make the StandardMaterial bindless index table have a fixed size regardless of the features that are enabled. (#18771)
Due to the preprocessor usage in the shader, different combinations of
features could cause the fields of `StandardMaterialBindings` to shift
around. In certain cases, this could cause them to not line up with the
bindings specified in `StandardMaterial`. This resulted in #18104.

This commit fixes the issue by making `StandardMaterialBindings` have a
fixed size. On the CPU side, it uses the
`#[bindless(index_table(range(M..N)))]` feature I added to `AsBindGroup`
in #18025 to do so. Thus this patch has a dependency on #18025.

Closes #18104.

---------

Co-authored-by: Robert Swain <robert.swain@gmail.com>
2025-04-09 20:39:42 +00:00
Brian Reavis
bc259fad04
Fix get_render_pipeline_state / get_compute_pipeline_state panic (#18752)
This fixes a panic that occurs if one calls
`PipelineCache::get_render_pipeline_state(id)` or
`PipelineCache::get_compute_pipeline_state(id)` with a queued pipeline
id that has not yet been processed by `PipelineCache::process_queue()`.

```
thread 'Compute Task Pool (0)' panicked at [...]/bevy/crates/bevy_render/src/render_resource/pipeline_cache.rs:611:24:
index out of bounds: the len is 0 but the index is 20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
2025-04-09 16:55:19 +00:00
charlotte
e8fd750274
Fix unbatchable meshes. (#18761)
# Objective

Fixes #18550.

Because bin state for unbatchable meshes wasn't being cleared each
frame, the buffer indices for unbatchable meshes would demote from
sparse to dense storage and aggressively leak memory, with all kinds of
weird consequences downstream, namely supplying invalid instance ranges
for render.

## Solution

Clear out the unbatchable mesh bin state when we start a new frame.
2025-04-09 15:35:33 +00:00
Patrick Walton
dc7c8f228f
Add bindless support back to ExtendedMaterial. (#18025)
PR #17898 disabled bindless support for `ExtendedMaterial`. This commit
adds it back. It also adds a new example, `extended_material_bindless`,
showing how to use it.
2025-04-09 15:34:44 +00:00
Freyja-moth
714b4a43d6
Change with_related to work with a Bundle and added with_relationships method (#18699)
# Objective

Fixes #18678

## Solution

Moved the current `with_related` method to `with_relationships` and
added a new `with_related` that uses a bundle.

I'm not entirely sold on the name just yet, if anyone has any ideas let
me know.

## Testing

I wasn't able to test these changes because it crashed my computer every
time I tried (fun). But there don't seem to be any tests that use the
old `with_related` method so it should be fine, hopefully

## Showcase

```rust
commands.spawn_empty()
    .with_related::<Relationship>(Name::new("Related thingy"))
    .with_relationships(|rel| {
        rel.spawn(Name::new("Second related thingy"));
    });
```

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2025-04-09 02:34:49 +00:00
Moony
0410212f3d
Expose the added tick for change detection, both getting and setting. (#18746)
# Objective

- Allow viewing and setting the added tick for change detection aware
data, to allow operations like checking if the value has been modified
since first being added, and spoofing that state (i.e. returning the
value to default in place without a remove/insert dance)

## Solution

- Added corresponding functions matching the existing `changed` API:
  - `fn added(&self) -> Tick`
  - `fn set_added(&mut self)`
  - `fn set_last_added(&mut self, last_added: Tick)`

Discussed on discord @
https://canary.discord.com/channels/691052431525675048/749335865876021248/1358718892465193060

## Testing

- Running the bevy test suite by.. making a PR, heck.
- No new tests were introduced due to triviality (i.e. I don't know what
to test about this API, and the corresponding API for `changed` is
similarly lacking tests.)

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
Co-authored-by: SpecificProtagonist <vincentjunge@posteo.net>
Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
2025-04-08 21:13:27 +00:00
ickshonpe
fb159f9846
Fix AccessKit node bounds (#18706)
# Objective

Fixes #18685

## Solution

* Don't apply the camera translation.
* Calculate the min and max bounds of the accessibility node rect taking
the UI translation relative to its center not the top-left corner.

## Testing

Install [NVDA](https://www.nvaccess.org/). In NVDA set `Preferences ->
Settings -> Vision -> Enable Highlighting`.

Then run bevy's `tab_navigation` example:
```
cargo run --example tab_navigation
```
If everything is working correctly, NVDA should draw a border around the
currently selected tab button:

![Screenshot 2025-04-07
130523](https://github.com/user-attachments/assets/07d9a795-5d55-4b61-9602-2e8917020245)
2025-04-08 01:42:02 +00:00
Jaso333
1b593ea8d4
clarified docs for bundle removal commands (#18754)
# Objective

Clarify information in the docs about the bundle removal commands.

## Solution

Added information about how the intersection of components are removed.
2025-04-07 22:34:59 +00:00