Seaside Studios
HomeOverviewFAQsContactReview
VFX Toolkit
VFX Toolkit
  • What is All In 1 VFX Toolkit
  • Overview
  • Setup and Render Pipelines
  • First Steps (Must Read)
  • Asset Component Features
  • Shader Structure and Usage
  • Advanced Configuration and Key Rendering Concepts
  • Particle System Helper Component
  • Asset Window
  • Textures Setup
  • Saving Prefabs
  • Screen Distortion and Creating Distortion Maps
  • Custom Vertex Streams and Custom Data Auto Setup
  • How to Animate Materials
  • Custom Scaled Time
  • Scripting
  • Visual Effect Graph (Vfx Graph)
  • How to Enable/Disable Effects at Runtime
  • Random Seed
  • Render Material To Image
  • Premade Textures, Meshes and Materials
  • Helper Scripts and Other Utilities
  • Lit Shader
  • Effects and Properties Breakdown
  • Custom Gradient Property Drawer
  • Running out of Shader Keywords
  • Considerations
  • FAQ (Frequently Asked Questions)
  • Credits
Powered by GitBook
On this page

How to Enable/Disable Effects at Runtime

PreviousVisual Effect Graph (Vfx Graph)NextRandom Seed

Last updated 7 months ago

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("GLOW_ON");
mat.DisableKeyword("GLOW_ON");

(Keyword names of every effect can be found at the Effects and Properties Breakdown section)

If you really want to use this feature and you really know what you are doing and how to prevent the aforementioned errors you can also find the effect name by hovering it with the mouse in the Material Inspector: