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. Dismiss Notice

Cant change a float value in a Shader Graph

Discussion in 'Shader Graph' started by Stew_79, Apr 16, 2021.

  1. Stew_79

    Stew_79

    Joined:
    Feb 24, 2021
    Posts:
    36
    Hi guys as the title states, I am having trouble changing a float value in an Outline shader Graph.
    The shader graph works perfect and I want to control it through a c# sharp script that is attached to my main player object.
    I have created a material with the shader graph and attached it to my main player

    Code (CSharp):
    1.  Ship = GetComponent<Rigidbody2D>();
    2.         animator = GetComponent<Animator>();
    3.         gameController = FindObjectOfType<GameController>();//find GameController script might be better to do this rather than making the vairables static?
    4.         spawner = FindObjectOfType<WaveSpawner>();
    5.         audioSource = GetComponent<AudioSource>();
    6.         spriteRenderer = GetComponent<SpriteRenderer>();
    7.         gameController.PlayerAlive = true;
    8.         spawner.waveSpawner = true;
    9.         stealth(3f);
    10.         powerUp = 0;
    11.         defaultColour = new Color32(0, 97, 255, 255);//set colours
    12.         selectedColour = new Color32(252, 12, 132, 255);
    13.         maxColour = new Color32(0, 0, 0, 255);
    14.         inUseColour = new Color32(127, 233, 255, 255);
    15.         inVincibleColour = new Color32(127, 233, 255, 255);
    16.         hurtColour = new Color32(252, 12, 96, 255);
    17.         playerColour = new Color32(176, 88, 214, 255);
    18.  
    19.        // playerMaterial = GetComponent<SpriteRenderer>().material;
    20.         playerMaterial = spriteRenderer.material;
    I then get the sprite renderer component in start
    Then I want to change the _Thickness property, in my stealth method

    Code (CSharp):
    1.     public void stealth(float stealthTime) //pass in time for stealth
    2.     {
    3.         timer = stealthTime;
    4.  
    5.         if (weaponMax[gameController.t] != true)
    6.         {
    7.             lineThickness = 0.005f;
    8.             playerMaterial.SetFloat("_Thickness", lineThickness);
    9.  
    10.             isInvicilbe = true;
    11.             weaponMax[gameController.t] = true;
    12.             gameController.UItext[gameController.t].color = maxColour;
    13.                                                                  
    14.  
    15.             spriteRenderer.color = new Color32(127, 233, 255, 255);
    16.          
    17.         }
    I am getting a
    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.stealth (System.Single stealthTime) (at Assets/Scripts/PlayerController.cs:339)
    PlayerController.Start () (at Assets/Scripts/PlayerController.cs:72)

    Screenshot (11)_LI.jpg Screenshot (12)_LI.jpg
     
    Last edited: Apr 16, 2021
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,511
    I don't know how to help you here but wanted to mention that there's a dedicated forum for Shader Graph.
     
    Stew_79 likes this.
  3. Stew_79

    Stew_79

    Joined:
    Feb 24, 2021
    Posts:
    36
    Ok Thanks will try there
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,511
    I can move your thread for you.
     
    Stew_79 likes this.
  5. Stew_79

    Stew_79

    Joined:
    Feb 24, 2021
    Posts:
    36
    If you could that would be great thanks @MelvMay
     
    MelvMay likes this.