-
-
Notifications
You must be signed in to change notification settings - Fork 938
Looks like UniTask.Yield(PlayerLoopTiming.Update) is not resuming at Update sometimes #561
-
|
Hello, I'm using Unity 2023年2月11日f1 and UniTask 2.5.4. SummaryTo be short, it looks to me that await UniTask.Yield(PlayerLoopTiming.Update, cancellationToken: cancel); is not resuming the execution flow at Update sometimes and the behaviour is not repeatable. ProcedureThat is, I started from a Standard (URP) scene, created an empty GameObject, added MyUniTaskTest component as below.. using Cysharp.Threading.Tasks; using System.Threading; using UnityEngine; public class MyUniTaskTest : MonoBehaviour { string _phase; bool _done; void OnEnable() { _done = false; } void FixedUpdate() { _phase = "FixedUpdate_Begin"; _phase = "FixedUpdate_End"; } void Update() { _phase = "Update_Begin"; if (!_done) { _done = true; MyTaskAsync(destroyCancellationToken).Forget(); } _phase = "Update_End"; } void LateUpdate() { _phase = "LateUpdate_Begin"; _phase = "LateUpdate_End"; } async UniTaskVoid MyTaskAsync(CancellationToken cancel) { print($"MyTaskAsync"); for (int i = 0; i<30; i++) { print($"{i}: {Time.frameCount} {_phase}"); await UniTask.Yield(PlayerLoopTiming.Update, cancellationToken: cancel); } } } Run the scene in Play mode. ResultsWhat's printed in the Console was as follows.
ExpectedIf the task is resumed at the timing of Update, which is after FixedUpdate and before LateUpdate, the output would be either FixedUpdate_End, Update_Begin, or Update_End. Why is LateUpdate_End printed sometimes? Correct me if I am using the API wrongly or I I misunderstand something. |
Beta Was this translation helpful? Give feedback.
All reactions
FixedUpdate is not guaranteed to run every frame. PlayerLoopTiming.Update runs before your MonoBehaviour's Update in the frame. Therefore, the only things it could ever be are Update_Begin FixedUpdate_End or LateUpdate_End, because FixedUpdate_End or LateUpdate_End were the last things to be updated on the previous frame.
Replies: 1 comment 1 reply
-
FixedUpdate is not guaranteed to run every frame. PlayerLoopTiming.Update runs before your MonoBehaviour's Update in the frame. Therefore, the only things it could ever be are Update_Begin FixedUpdate_End or LateUpdate_End, because FixedUpdate_End or LateUpdate_End were the last things to be updated on the previous frame.
Beta Was this translation helpful? Give feedback.
All reactions
-
😄 1
-
PlayerLoopTiming.Update runs before your MonoBehaviour's Update in the frame.
Aha, then it makes sense. Thank you!
Because the test project runs with Time / Fixed Timestamp = 0.02, Quality / VSync Count = Every V Blank, and my display has 120Hz frequency, FixedUpdate is called less frequently than Update.
Suppose at the n-th frame ended. _phase = "LateUpdate_End";
Then starts (n+1)-th frame without FixedUpdate. UniTask runs before MyUniTaskTest.Update. So I see LateUpdate_End.
Beta Was this translation helpful? Give feedback.