fix: Avoid reading eased entities mutably, until there is an intention to mutate them #31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello!
So this began with a short problem I had where any eased Component had it's
Changed<T>
triggered on every Update.This PR kind of does two things, and there's also an example which helped me debug and implement these changes.
1. Only trigger
Changed<T>
/read mutably when necessary.This was the main issue I had, and the change is splitting the query into two:
entity_query: Query<Entity, With<T>>
andmut object_query: Query<&mut T>
.Get entity early, but hold off on fetching the object with
get_mut()
until needed, since callingget_mut()
triggers the bevy_change detection (whether you change the object or not).2. Don't evaluate animations if state is not
EasingState::Play
This became part of this PR, after noticing that if the animation state is paused, it will keep recalculating the animation state (and triggering
Changed<T>
) forever. I don't see any reason why we need to redo any of the logic there, since we can more or less be guaranteed that it will keep being the same... Forever? Right?3. The controlled.rs example
This is just a file that I used to make sure my changes works as intended, and I feel it's maybe too complex to really be an example, and would be happy to remove/simplify it if needed.