Skip to content

Scripting

Every effect property is a normal shader property, so you drive them with Unity’s own material API. Nothing asset specific is involved.

This comes up most on materials assigned to Mesh Renderers. On Particle Systems you will usually get further with the particle system’s own modules and Custom Vertex Streams, which feed values per particle rather than per material.

Three ways, in order of convenience:

  1. Hover over any property in the Material Inspector. The tooltip is the property name.
  2. Look it up on Effects and Properties Breakdown, which lists every one.
  3. Read the Properties block at the top of Assets\Plugins\AllIn1Assets\AllIn1VfxToolkit\Shaders\AllIn1Vfx.shader.

Shape properties follow one rule worth knowing: Shape 1 omits the number, Shapes 2 and 3 keep it. So the shape tint is _ShapeColor, _Shape2Color and _Shape3Color.

Material mat = GetComponent<Renderer>().material;
mat.SetFloat("_Alpha", 0.5f);
mat.SetColor("_Color", new Color(0.5f, 1f, 0f, 1f));
mat.SetTexture("_MainTex", texture);

SetFloat, SetColor and SetTexture cover almost everything the shader exposes. Sliders and toggles are floats, colours are colours, textures are textures.

renderer.material creates an instance the first time you touch it, so changes affect this object alone and you own a material Unity will not clean up until the object dies. renderer.sharedMaterial edits the asset itself, so every object using it changes, and in the editor that change is written to disk.

Use material for a per-object effect. Use sharedMaterial when you deliberately want everything to change at once.

A worked example: dissolving an effect out

Section titled “A worked example: dissolving an effect out”

_FadeAmount drives the dissolve, from -0.1 for untouched to 1 for fully gone. Enable Fade From Noise Texture on the material, then drive the amount:

using System.Collections;
using UnityEngine;
public class DissolveOut : MonoBehaviour
{
private static readonly int FadeAmount = Shader.PropertyToID("_FadeAmount");
[SerializeField] private float duration = 1f;
private Material mat;
private void Awake()
{
mat = GetComponent<Renderer>().material;
}
public void Dissolve()
{
StopAllCoroutines();
StartCoroutine(DissolveRoutine());
}
private IEnumerator DissolveRoutine()
{
for (float t = 0f; t < duration; t += Time.deltaTime)
{
mat.SetFloat(FadeAmount, Mathf.Lerp(-0.1f, 1f, t / duration));
yield return null;
}
mat.SetFloat(FadeAmount, 1f);
}
}

Two things worth copying from that. The property ID is cached with Shader.PropertyToID in a static readonly field, which is how you should address any property you set every frame, since the string version hashes the name on each call. The asset does the same thing internally, in AllIn1VfxScrollShaderProperty. And the effect stays enabled throughout, with only its amount moving, which is the recommended pattern explained on How to Enable/Disable Effects at Runtime.

If all you need is a property that moves over time, the asset ships two components for it: AllIn1VfxScrollShaderProperty for a float and AllIn1VfxScrollShaderTexture for a texture offset or scale. Both take the property name as a string and can loop, ping pong, or stop at a value. See Helper Scripts and Other Utilities.

UI materials are shared, so every Image using the same material asset shares one instance and a change to one changes all of them. The asset ships AllIn1GraphicMaterialDuplicate.cs to make a per-Image copy on Awake. See How to Animate Materials.

Masked UI elements render through a different material than the one in their slot, so write to materialForRendering instead:

image.materialForRendering.SetFloat("_FadeAmount", t);

The AddAllIn1Vfx component exists to set materials up in the editor. Do not call it from gameplay code. Once your material is set up you can remove the component, and leaving it costs nothing either way.