Mathf.SmoothDamp locking and severely impacting FPS

I’m expecting this to decrease the alpha of my GUI smoothly from 1f to 0f, however it simply flutters around 0.6f and drops the framerate to 20fps! I’ve decreased the smoothTime to 0.1f to simply try and spur the process into action, but eventually this will be changed to 1 second. I don’t understand what’s going on especially as I’ve spent hours looking at this and can’t seem to find fault in my code! I blame the useless Unity docs… unless of course I’m being an idiot :stuck_out_tongue:

Here’s the code:

void Start () {
    splash = Resources.Load<Texture2D> ("Splash");
    initTime = Time.time;
    smoothVelocity = 0f;
}
    	
void OnGUI () {
    
if (initTime + 4f < Time.time) {
    	Color newColor = GUI.color;
    	newColor.a = Mathf.SmoothDamp(newColor.a, 0f, ref smoothVelocity, 0.1f);
    
GUI.color = newColor;
}
//Show splash screen
GUI.DrawTexture (new Rect (0f, 0f, Screen.width, Screen.height), splash, ScaleMode.ScaleToFit);
}

OnGUI can be called multiple times per Update(). Try doing the Mathf.SmoothDamp in Update() or FixedUpdate() instead.

Also, this stuff

if (initTime + 4f < Time.time)

…shouldn’t be necessary. Just set your smooth time to 4.0f. (Unless I’m misinterpreting your code)