From 1047911cfe613a3d67ca1224cfbf8e75675f9552 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 16 Aug 2024 07:40:52 -0500 Subject: [PATCH] Fix initial lerp jumping for Progress bar on first update. --- Source/Engine/UI/GUI/Common/ProgressBar.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index 4852865bf..61e31b074 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -169,6 +169,9 @@ namespace FlaxEngine.GUI [EditorDisplay("Bar Style"), EditorOrder(2012), Tooltip("The brush used for progress bar drawing.")] public IBrush BarBrush { get; set; } + // Used to remove initial lerp from the value on play. + private bool _firstUpdate = true; + /// /// Initializes a new instance of the class. /// @@ -202,7 +205,7 @@ namespace FlaxEngine.GUI { // Lerp or not if running slow bool isDeltaSlow = deltaTime > (1 / 20.0f); - if (!isDeltaSlow && UseSmoothing) + if (!isDeltaSlow && UseSmoothing && !_firstUpdate) value = Mathf.Lerp(_current, _value, Mathf.Saturate(deltaTime * 5.0f * SmoothingScale)); _current = value; } @@ -213,6 +216,9 @@ namespace FlaxEngine.GUI } base.Update(deltaTime); + + if (_firstUpdate) + _firstUpdate = false; } ///