bevy/crates/bevy_ecs/src
Robert Walter e7ab65675d
Update docs of set_if_neq and replace_if_neq (#12919)
# Objective

- ~~This PR adds more flexible versions of `set_if_neq` and
`replace_if_neq` to only compare and update certain fields of a
components which is not just a newtype~~
- https://github.com/bevyengine/bevy/pull/12919#issuecomment-2048049786
gave a good solution to the original problem, so let's update the docs
so that this is easier to find

## Solution

- ~~Add `set_if_neq_with` and `replace_if_neq_with` which take an
accessor closure to access the relevant field~~

---

In a recent project, a scenario emerged that required careful
consideration regarding change detection without compromising
performance. The context involves a component that maintains a
collection of `Vec<Vec2>` representing a horizontal surface, alongside a
height field. When the height is updated, there are a few approaches to
consider:

1. Clone the collection of points to utilize the existing `set_if_neq`
method.
2. Inline and adjust the `set_if_neq` code specifically for this
scenario.
3. (Consider splitting the component into more granular components.)

It's worth noting that the third option might be the most suitable in
most cases.

A similar situation arises with the Bevy internal Transform component,
which includes fields for translation, rotation, and scale. These fields
are relatively small (`Vec3` or `Quat` with 3 or 4 `f32` values), but
the creation of a single pointer (`usize`) might be more efficient than
copying the data of the other fields. This is speculative, and insights
from others could be valuable.

Questions remain:

- Is it feasible to develop a more flexible API, and what might that
entail?
- Is there general interest in this change?

There's no hard feelings if this idea or the PR is ultimately rejected.
I just wanted to put this idea out there and hope that this might be
beneficial to others and that feedback could be valuable before
abandoning the idea.
2024-04-15 12:38:38 +00:00
..
entity Clean up some low level dependencies (#12858) 2024-04-08 19:45:42 +00:00
identifier fix some typos (#12038) 2024-02-22 18:55:22 +00:00
query Add archetypal to Access Debug impl (#12947) 2024-04-13 06:06:48 +00:00
reflect Make some ReflectComponent/ReflectBundle methods work with EntityMut too (#12895) 2024-04-08 01:46:07 +00:00
schedule Remove the system task span (#12950) 2024-04-13 19:27:11 +00:00
storage Document the lifetime requirement of byte_offset and byte_add (#12893) 2024-04-08 17:13:35 +00:00
system Add EntityWorldMut::remove_by_id (#12842) 2024-04-03 09:50:32 +00:00
world Implement From<&'w mut EntityMut> for EntityMut<'w> (#12896) 2024-04-07 13:24:10 +00:00
archetype.rs Adding some docs for archetype internals (#12578) 2024-03-23 01:48:31 +00:00
bundle.rs Update safety comment for bundle removal (#12657) 2024-03-23 22:07:08 +00:00
change_detection.rs Update docs of set_if_neq and replace_if_neq (#12919) 2024-04-15 12:38:38 +00:00
component.rs Optimize Event Updates (#12936) 2024-04-13 14:11:28 +00:00
event.rs Optimize Event Updates (#12936) 2024-04-13 14:11:28 +00:00
intern.rs Moves intern and label modules into bevy_ecs (#12772) 2024-04-08 15:34:11 +00:00
label.rs Moves intern and label modules into bevy_ecs (#12772) 2024-04-08 15:34:11 +00:00
lib.rs Moves intern and label modules into bevy_ecs (#12772) 2024-04-08 15:34:11 +00:00
removal_detection.rs Add RemovedComponentEvents::iter (#12815) 2024-04-01 20:20:30 +00:00