From 1047911cfe613a3d67ca1224cfbf8e75675f9552 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 16 Aug 2024 07:40:52 -0500 Subject: [PATCH 1/2] 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; } /// From 7772669148f44b9ac4b4f364f550f50f81a30fbd Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 16 Aug 2024 07:46:31 -0500 Subject: [PATCH 2/2] Better fix. --- Source/Engine/UI/GUI/Common/ProgressBar.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/Engine/UI/GUI/Common/ProgressBar.cs b/Source/Engine/UI/GUI/Common/ProgressBar.cs index 61e31b074..67f521c4a 100644 --- a/Source/Engine/UI/GUI/Common/ProgressBar.cs +++ b/Source/Engine/UI/GUI/Common/ProgressBar.cs @@ -143,9 +143,11 @@ namespace FlaxEngine.GUI if (!Mathf.NearEqual(value, _value)) { _value = value; - if (!UseSmoothing) + if (!UseSmoothing || _firstUpdate) { _current = _value; + if (_firstUpdate) + _firstUpdate = false; } } } @@ -205,7 +207,7 @@ namespace FlaxEngine.GUI { // Lerp or not if running slow bool isDeltaSlow = deltaTime > (1 / 20.0f); - if (!isDeltaSlow && UseSmoothing && !_firstUpdate) + if (!isDeltaSlow && UseSmoothing) value = Mathf.Lerp(_current, _value, Mathf.Saturate(deltaTime * 5.0f * SmoothingScale)); _current = value; } @@ -216,9 +218,6 @@ namespace FlaxEngine.GUI } base.Update(deltaTime); - - if (_firstUpdate) - _firstUpdate = false; } ///