- Home /
ExecuteAlways does not work as expected in 2021 LTS
I'm having issues with [ExecuteAlways]
in Unity 2021.3.1f1 (LTS) the code does not update in my scene unless I keep clicking the mouse button. Each click it steps about 0.1 seconds in time. But when I run the same code in 2020.3.23f1 it works as expected and the object moves smoothly without having to repeatedly click the mouse button. I do have 'Always Refresh' enabled in the viewport settings.
Is is there some new setting that need to be set somewhere in the new version of Unity to support real-time update of the Update method in the scene view or is this a bug?
Here is an simplified version of the code I'm running, and as I said it works in 2020 but not 2021.
[ExecuteAlways]
public class Demo : MonoBehaviour
{
public GameObject obj;
public Vector3 startPos = Vector3.zero;
public Vector3 startPos = Vector3.one;
public float duration = 2.0f;
private bool animate = true;
private float currentLerpTime = 0f;
private void Update()
{
if (animate)
{
currentLerpTime += Time.deltaTime;
if (currentLerpTime > duration)
{
currentLerpTime = duration;
animate = false;
}
float perc = currentLerpTime / duration;
obj.transform.localPosition = Vector3.Lerp(startPos, endPos, perc);
}
}
}
See this forum thread for more information and a workaround. https://forum.unity.com/threads/executealways-doesnt-work-in-unity-2021-3-1f1-lts.1276256/