Search Unity

Question Is there any way to change material properties of a VFX Graph that uses a Shader Graph?

Discussion in 'Visual Effect Graph' started by SniperED007, Feb 16, 2023.

  1. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    345
    Using Unity 2022.1.24f1

    A have a VFX Graph that uses a Shader Graph, during runtime I want to reference the material it's using to enable / disable the Cast Shadows option:

    I tried assigning this material:
    upload_2023-2-16_14-6-2.png
    material.SetFloat("_CastShadows", 0);

    I can see the material changes in the inspector, but the shadows still get cast, so the VFX Graph must be using an instance of that material, but how do I get that instance?
     
  2. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    I'm exactly in in your situation now and still searching for that material instance >.<
    I want to use "material.SetBuffer" for the shadergraph material. As I'm using the shaders Setup() function to do some stuff.
     
  3. Zyblade

    Zyblade

    Joined:
    Jul 1, 2014
    Posts:
    141
    Okay, found it. On the gameobject with the VisualEffect component, just do the following:
    GetComponent<Renderer>().material
    As the VisualEffect component also adds the renderer component. And this has the material instance.