Lerp gets caled only once in Update function

Why dosen’t this work i mean its Update its being called every frame, but lerp gets called only once.And Lerp does get called just only once thats double confirmed. it works just not as expected.

Anyways here’s the Code:

 void Start ()
    {
        rend = GetComponent<Renderer>();
        rend.material.shader = Shader.Find ("FresnelPack/Transparent Rim Unlit");
        //rend.material.SetFloat ("_Scale", 0.0f);
        }
    }
    void Update ()
    {
        rend.material.SetFloat ("_Scale", Mathf.Lerp (0.8f, 0f, Time.deltaTime * 10));
    }

Can you try doing this :

rend.material.SetFloat ("_Scale", Mathf.Lerp (rend.material.GetFloat("_Scale"), 0f, Time.deltaTime * 10));

You think that but you’re 100% wrong of course.

You’re just using it wrong in this case since the result isn’t being assigned here, so the Lerp is behaving like a constant.

Instead, pass in a variable for t.

This is how NOT to use Lerp.

Try Mathf.Lerp(0.8f, 0f, t) where t is a variable defined in the class that you change over time.

Thanks for the quick responses everyone the lineupthesky’s solution worked for me.

Yeah although his solution isn’t very good practise since its slower to constantly read a variable via renderer, then material. Has other problems that can happen too but each to their own.

Ofcourse it’s not a constant solution. But in order to optimize it a little bit, this can be done :

public Material mat_Target; // Assign your material over here instead of getting it from Renderer component.
private float f_Assigned; // We will lerp this variable instead of getting Material's properties.
public float f_LerpingSpeed; // With this speed the lerp will perform.
IEnumerator LerpCoroutine(float lerpTo)
{
float i = 0.0f;
float rate = 1.0f / f_LerpingSpeed;
float current  = mat_Target.GetFloat("_Scale");
f_Assigned = current;
while(i < 1.0f)
{
i += Time.deltaTime * rate;
f_Assigned = Mathf.Lerp(current, lerpTo, i);
mat_Target.SetFloat("_Scale", f_Assigned);
yield return null;
}
}

Just call this function using StartCoroutine(LerpCoroutine(0.5f)); when you want your variable to be lerped. ( 0.5f is an example, in your case, 0.0f )