Page 1 of 1

Animating a switch on and off

PostPosted: Sun Jan 27, 2019 3:53 pm
by jzza
Hi

I have a switch in a shader which works when I use it in the inspector but if I try to animate it (using 0 for off and 1 for on) then it doesn't work, am I doing something wrong?
I'm using the Unity animator and keyframing the states.

Thanks

Re: Animating a switch on and off

PostPosted: Sun Jan 27, 2019 6:25 pm
by jzza
I've got this working now, I've now used a toggle switch instead of a static switch and the toggle works fine when animated. Not sure why the static switch doesn't animate.

Re: Animating a switch on and off

PostPosted: Tue Jan 29, 2019 9:17 am
by Amplify_Borba
Hello, thank you for getting in touch and for your support!

In order to allow the shader to be changed in runtime through the Static Switch node, you likely need to set its Keyword Type property to Multi Compile, as it will generate all shader variants and include them all in the build. The Shader Feature type will only generate the used variants, and will only include in the build the active one, making it extremely efficient.

To clarify, the general purpose of the Static Switch node is to allow for the generation of a number of shader variants, which are generated internally by Unity depending on the type of Keyword that you're using.

In short, Toggles are comparable to Lerp nodes, as they execute all calculations, while Static Switches can execute only what you define.

Re: Animating a switch on and off

PostPosted: Tue Jan 29, 2019 2:18 pm
by jzza
Thanks very much, I understand now.

Re: Animating a switch on and off

PostPosted: Tue Jan 29, 2019 4:25 pm
by Amplify_Borba
Happy to help, please let us know if you come across any further questions, thanks!