UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[Animator] Erases MaterialPropertyBlock: Restore Visuals

Under Audit

animatorgraphics

Unity 2022.3.x - Unity 6.1.x

Published Fri, Mar 20

Destroying a temporary Animator component can unexpectedly reset material properties previously set with a MaterialPropertyBlock, reverting them to default values even after the Animator is destroyed.

Issue

 When a temporary Animator component is created to animate material properties, specifically when using a MaterialPropertyBlock, and subsequently destroyed, the animated material properties may unexpectedly revert to their default values. This behavior occurs even if the MaterialPropertyBlock is updated after the Animator is destroyed. In contrast, material color changes made directly via Material.color or Material.SetColor("_Color", ...) persist after the Animator is destroyed, though these methods force the creation of material instances. The issue specifically arises when a MaterialPropertyBlock is used to modify properties, leading to an unwanted reset of values (e.g., color reverting to white) instead of maintaining the last set or animated state. This necessitates storing and reapplying base colors, adding complexity to workflows that require immediate Animator destruction and subsequent material property updates.

Experimental Fixes
  • Store the material properties in a separate variable before destroying the Animator and reapply them using Material.SetPropertyBlock after destruction.
  • Instead of destroying the Animator immediately, consider disabling its component or deactivating its GameObject to see if the property values persist.
  • Ensure that no other scripts or Animation curves are inadvertently resetting material properties after the Animator is destroyed.

Editor's Note:

The above fixes have not been verified by our audit team yet. They are provided exclusively for your own technical research. We recommend creating a backup of your project before proceeding with any attempts. Utilize at your own discretion!

Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.