Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Accessing Shader Graph's properties from C# script

Discussion in 'Scripting' started by daud7078, May 29, 2018.

  1. daud7078

    daud7078

    Joined:
    Jan 10, 2018
    Posts:
    2
    Hi. I'm trying to access properties of Shader Graph via C# Script.

    I've created a PBR shader graph named "TV_screen_graph"
    I've created two properites : emission_intensity(vector 1) and movie_texture(texture 2D asset) in my shader graph.
    I've created a material named TV_screen_mat and chose the TV_screen_graph
    I've assigned the TV_screen_mat to my mesh

    Now, I want to control the emission_intensity and start the movie_texture to play via C# script

    I've tried

    Code (CSharp):
    1.     void Start () {
    2.  
    3.         Renderer r = GetComponent<Renderer>();
    4.         MovieTexture movie = (MovieTexture)r.material
    5.  
    6.         movie.Play();
    7.     }
    8.    
    to play the movie texture, it failed, and I know things don't work that way with shader graph material but I have no idea how to access the properties from shader graph.

    Someone pls help me. Thanks.
     
    Last edited: May 30, 2018
  2. Pavlon

    Pavlon

    Joined:
    Apr 15, 2015
    Posts:
    191
  3. daud7078

    daud7078

    Joined:
    Jan 10, 2018
    Posts:
    2
    What I am saying is I am using shader graph which is a new feature included in Unity 2018. Not a standard material.
    What I want to do is I want to play the movie texture that I imported into shader graph. Not on the camera background as the doc says.
    I want to change the emission intensity of the Shader Graph with C# script, not the emission intensity of the standard material.

    I need to know how to access the properties of the Shader Graph which is imported into material via C# Script.

    Thanks.
     
  4. JoeTheGG

    JoeTheGG

    Joined:
    Aug 18, 2013
    Posts:
    42
  5. Bilalazhar95

    Bilalazhar95

    Joined:
    Nov 29, 2017
    Posts:
    1
    Open shader graph where you name the property, there is a textbox saying "Reference" name your property there. Shader graph will rename it with underscores. Use this name in your script