Seaside Studios
3D Shader
3D Shader
  • What is All In 1 3D Shader
  • Overview
  • First Steps (Must Read)
  • URP And Post Processing Setup
  • Asset Component Features
  • Asset Window
  • Saving Prefabs
  • Convert Materials to 3D Shader
  • Light Models
  • Effects List
  • Scripting
  • Batch Override Materials
  • How to animate effects
  • Advanced Configuration and Key Rendering Concepts
  • How to Enable/Disable Effects at Runtime
  • Random Seed
  • Scaled Time
  • Outlines
  • Wind Effect and Wind Controller
  • Depth Coloring - Stylized Fog
  • Shadow Color
  • Fast Lighting
  • Performance Considerations
  • FAQ (Frequently Asked Questions)
Powered by GitBook
On this page

How to Enable/Disable Effects at Runtime

There are 2 ways of achieving this:

  1. All effects have a property value combination that makes them look deactivated (usually by reducing the amount or blend property to 0, but it may vary depending on the effect). So the most clean way of deactivating and activating effects is by enabling all the effects you’ll use and then dynamically changing the property values either by animating the properties or by modifying the values by script as seen in the Scripting section.

  2. This other way is less efficient, messier and will cause materials to become invisible in the final build if you set a combination of effects that isn’t included in some other material in your project. So be warned, use this with caution (in fact you should probably avoid this option and use option 1 instead) and test it on the target platform. If material effects disappear or you get a graphics error (object turns pink) at some point make sure to have some material in your project that includes the same set of effects than the material that isn’t showing. This method consists on enabling and disabling the shader compilation flags at runtime, so Unity will compile and replace the shader at runtime (on a final build shaders can’t be compiled, so a shader variant with the new keywords will need to be available to avoid the errors mentioned). If you are sure to have a shader variant for the resulting toggle combination you can use the Enable/Disable Keyword method like so:

Material mat = GetComponent<Renderer>().material;
…
mat.EnableKeyword("_EMISSION_ON");
mat.DisableKeyword("_EMISSION_ON");
PreviousAdvanced Configuration and Key Rendering ConceptsNextRandom Seed

Last updated 1 month ago