Hi,
I have a bunch of custom shaders that I want to be able to control using an animator controller and animation clips. Is this possible?
I’ve tried adding an animation controller/clip to the object with the shader/material applied to it, but when I go to the animation dope sheet and try to add a shader property to the animation it doesn’t seem to be available.
For example I have a shader with a blur effect that is controlled by a slider called “magnitude”. When I go to the animation window, I can see the “standard” properties to add, like colour, for example. But my own properties are missing.
Is there something I need to add to the properties to make them exposed to the animator?
Thanks
You may create custom script for that with properties you want.
public float myCustomFloat {
get { return GetComponent<MeshRenderer>().sharedMaterial.getFloat("myCustomFloat"); }
set { GetComponent<MeshRenderer>().sharedMaterial.setFloat("myCustomFloat", value); }
}
What version of Unity are you using? What kind of component are you looking to animate? How are you creating the animation?
In 2018.2 if I select a game object with a mesh renderer component, go to the Animation tab and create a new clip, I can see all of the properties of the material listed in the Properties block of the shader. Just for an example, here’s a custom circular bar shader with a lot of non-standard property names. They all show up.
This works in 2019, and worked in 2017 and all versions of Unity 5.
For a UI element the material properties are not showing up in the animator. Even if I right click on a property I don’t get the “add keyframe” option.
As a workaround I’ll trigger an animation event and animate from there, but that breaks the preview, and complicates the animation process.
Is there a way to animate the material properties from a custom script? Example, when I have this:
public class Blerp : MonoBehaviour
{
public Material materialField; // Nope
[field: SerializeField] public Material materialProperty { get; set; } // Nada
}
In my animation window I see Blerp.materialField, and Blerp.materialProperty, but not say Blerp.materialField_Base Color.
I can see it has to do with MaterialPropertyBlock, as material and sharedMaterial on a renderer never change, but the GetPropertyBlock does, but I don’t know how to use that to my advantage.