Search Unity

Shader Graph vertex modification functioning differently during runtime

Discussion in 'Editor & General Support' started by BigRookGames, Jan 10, 2019.

  1. BigRookGames

    BigRookGames

    Joined:
    Nov 24, 2014
    Posts:
    330
    I have created a shader graph that modifies the position of the mesh, kind of like a wobble effect. When I am modifying the shader while not in runtime, it is capable of moving in all directions, and when I hit play it moves the same in runtime UNTIL i change one of the variables of the shader graph. The object makes the shader an instance of the shader and then all of the sudden it does not move in the x direction at all, even with the same variables it had when it was not an instance of the shader.
    Am I missing something here? Does anyone know what might be going on here? Does something change fundamentally with the execution of a shader after it is instanced?
    I don't think it would be anything I am calling from code but I'm not sure, here is the script:
    Code (CSharp):
    1. public class DamageWobble : MonoBehaviour {
    2.  
    3.     public float dampingSpeed;
    4.     public float stretchDistance, stretch;
    5.     private bool wobbleEnabled;
    6.     public Vector3 damageDirection;
    7.  
    8.     private void Update()
    9.     {
    10.         if (wobbleEnabled)
    11.         {
    12.             bool doneUpdating = true;
    13.  
    14.             foreach (Material mat in GetComponent<MeshRenderer>().materials)
    15.             {
    16.                 if (stretch <= 0)
    17.                 {
    18.                     stretch = 0;
    19.                 }
    20.                 else
    21.                 {
    22.                     doneUpdating = false;
    23.                     mat.SetFloat("_stretch", stretch);
    24.                 }
    25.             }
    26.             if (doneUpdating)
    27.             {
    28.                 wobbleEnabled = false;
    29.             }
    30.             stretch = stretch - Time.deltaTime * dampingSpeed;
    31.         }
    32.     }
    33.  
    34.     private void ObjectHit(Vector3 hitPoint, Vector3 hitDirection)
    35.     {
    36.         foreach(Material mat in GetComponent<MeshRenderer>().materials)
    37.         {
    38.             mat.SetVector("_point_of_bend", hitPoint);
    39.             mat.SetVector("_direction", hitDirection);
    40.             mat.SetFloat("_stretch", stretchDistance);
    41.         }
    42.         stretch = stretchDistance;
    43.         damageDirection = hitDirection;
    44.         wobbleEnabled = true;
    45.     }
    46. }