Skip to content

Commit

Permalink
Avoid: Coroutine couldn't be started because the the game object 'Cur…
Browse files Browse the repository at this point in the history
…ves' is inactive!
  • Loading branch information
acidbubbles committed Oct 30, 2022
1 parent 3a9ee2b commit 1cca19e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/UI/Components/Curves/Curves.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Curves : MonoBehaviour
private readonly List<ControllerLineDrawer3D> _lines3D = new List<ControllerLineDrawer3D>();
private AtomAnimationEditContext _animationEditContext;
private float _lastClipTime;
private Coroutine _drawCurvesCo;

public Curves()
{
Expand Down Expand Up @@ -216,6 +217,11 @@ private void OnEnable()
private void OnDisable()
{
DestroyDeps();
if (_drawCurvesCo != null)
{
StopCoroutine(_drawCurvesCo);
_drawCurvesCo = null;
}
}

private void CreateDeps(ICurveAnimationTarget target)
Expand Down Expand Up @@ -323,7 +329,13 @@ private void DestroyDeps()

private void OnAnimationKeyframesRebuilt()
{
StartCoroutine(DrawCurveLinesDeferred());
if (!isActiveAndEnabled) return;
if (_drawCurvesCo != null)
{
StopCoroutine(_drawCurvesCo);
_drawCurvesCo = null;
}
_drawCurvesCo = StartCoroutine(DrawCurveLinesDeferred());
}

private IEnumerator DrawCurveLinesDeferred()
Expand All @@ -332,6 +344,7 @@ private IEnumerator DrawCurveLinesDeferred()
yield return 0;
yield return 0;
DrawCurveLinesImmediate();
_drawCurvesCo = null;
}

private void DrawCurveLinesImmediate()
Expand Down

0 comments on commit 1cca19e

Please sign in to comment.