Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Use code to change an exposed ShaderGraph Value?

Discussion in 'Shader Graph' started by TiggyFairy, Jun 5, 2023.

  1. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    480
    Hello, I want to let the player to be able to set certain values attached to custom ShaderGraph shaders in the options. The nearest I've come to being able to do this is the following code - which doesn't seem to work. Any idea why? I only started on ShaderGraph today so I don't even know if this is possible..

    Code (CSharp):
    1. renderer.materials[1].SetFloat("test", 9);
    Also, does anyone know a good way to make a nice clean outline around 3D objects in HDRP? I can't find anything online.
     
  2. IllTemperedTunas

    IllTemperedTunas

    Joined:
    Aug 31, 2012
    Posts:
    782
    Yeah, totally possible, people do it all the time. Try:
    Code (CSharp):
    1. renderer.materials[1].SetFloat("_test", 9f);
    Most internal names will put an underscore at the start:
    upload_2023-6-6_12-27-47.png
    So even though I called this property "Fresnel" if you want to change it through code you need to call it "_Fresnel", in your case instead of "test" try "_test"
     
    TiggyFairy likes this.
  3. TiggyFairy

    TiggyFairy

    Joined:
    Dec 22, 2019
    Posts:
    480
    Ah, cool! Thank you!