It seems strange that Material.Lerp isn’t static when the other Lerps are static.
Is there a reason why Material.Lerp modifies a material when the other Lerps return something?
It seems strange that Material.Lerp isn’t static when the other Lerps are static.
Is there a reason why Material.Lerp modifies a material when the other Lerps return something?
Material.Lerp()
is non-static because Material is a reference type.
If it was static, it would either have to …
A) return a new instance of Material every time it’s called (Memory allocation + draw call nightmare)
B) it would have to modify the “start” or “end” material passed in as parameter (would cause start/end point of Lerp to change, which would skew the whole operation)
C) it would have to take in the material being modified as a 4th parameter and modify it “secretly” inside the function (which would make it look different compared to the other Lerp functions and make it less obvious which variable is actually being modified)
And reversely, Vector3.Lerp
, Mathf.Lerp()
and Color.Lerp()
return a value because Color
, float
and Vector3
are value types.
You can’t make a function that modifies a value type declared outside the scope of the function unless you use “trickery” like the " out
" or " ref
" keywords, so you have to get the result as a return value.
void increment(int intgr)
{
intgr++;
}
int a = 100
increment(a); // doesn't work on value types
// a is still 100
In the end it’s of course a choice by whoever did the Unity API, but these are some of the semantic and logical reasonings for doing it like it is now.