How to animate effects
The custom material inspector properties can be animated through the Animation window as any other Unity component.
Using the Animation window
Section titled “Using the Animation window”If you don’t know how this is done you can follow this video:
Using scripting or a tweening library
Section titled “Using scripting or a tweening library”Alternatively you can also use scripting to animate your properties however you want or a Tweening Library, like my personal favourite: DOTween.
Animating with DOTween
Section titled “Animating with DOTween”DOTween can tween a material property directly, which makes it the easiest route for anything you want to trigger from code. Everything below needs using DG.Tweening;.
Enable the effect in the Material Inspector first. Tweening a property does nothing while its effect is off.
A single pass
Section titled “A single pass”A hit flash, driving _HitBlend up and letting it fall back:
using UnityEngine;using DG.Tweening;
public class FlashOnHit : MonoBehaviour{ private Material mat;
private void Awake() { mat = GetComponent<Renderer>().material; }
public void Flash() { mat.SetFloat("_HitBlend", 1f); mat.DOFloat(0f, "_HitBlend", 0.2f).SetLink(gameObject); }}SetLink(gameObject) kills the tween if the object is destroyed. Without it a tween outliving its material throws.
A repeating pulse with a pause
Section titled “A repeating pulse with a pause”For something that fires, waits, and fires again in the same direction, use a Sequence with LoopType.Restart. Yoyo would run the second half backwards, which is rarely what a pulse should look like.
using UnityEngine;using DG.Tweening;
public class RimPulse : MonoBehaviour{ [SerializeField] private float riseDuration = 0.4f; [SerializeField] private float pauseBetween = 1.5f;
private Sequence sequence;
private void Start() { Material mat = GetComponent<Renderer>().material;
sequence = DOTween.Sequence(); sequence.AppendCallback(() => mat.SetFloat("_MaxRim", 0f)); sequence.Append(mat.DOFloat(1f, "_MaxRim", riseDuration)); sequence.AppendInterval(pauseBetween); sequence.SetLoops(-1, LoopType.Restart); sequence.SetLink(gameObject); }}The callback resets the property at the top of every loop, so each pass starts from the same place no matter where the previous one ended. The same shape works for any property: _FadeAmount, _EmissionSelfGlow, _HueShift, whatever the effect needs. Property names are on Effects and Properties Breakdown.
