-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid unnecessary change detection resulting from component lens #91
Labels
enhancement
New feature or request
Comments
A workaround is to create a proxy component that acts continuously (by syncing with the |
djeedai
added a commit
that referenced
this issue
Apr 26, 2024
Add the ability for all `Lens`es to avoid triggering change detection if they don't make any actual change to their target (component or asset). This change modifies the signature of `Lerp::lerp()` to take `&mut dyn Targetable<T>` instead of `&mut T`. The `Targetable<T>` acts as a `Mut<T>`, marking the target as changed only if actually dereferenced mutably. Note that we cannot use `Mut<T>` directly because we can't obtain a `Mut<A: Asset>` without marking the asset as mutable; see bevyengine/bevy#13104. Fixes #91
@bonsairobo better late than never ;) this should work now, by mean of |
@djeedai Thanks! I'll give it a try when I jump back into my project. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now the
Lens
trait'slerp
method takes&mut T
forT: Component
, but it should only needMut<T>
.The system invokes
DerefMut
so we have no chance to avoid change detection in a custom lens:bevy_tweening/src/plugin.rs
Line 87 in 3c6b10e
Specifically, I have a custom lens that acts like a discrete switch that changes from one value to another at a specific
ratio
. This would only require a singleDerefMut
, but in fact it happens every frame that theAnimator
is running.The text was updated successfully, but these errors were encountered: