[BUG] Error when creating new Sequences
Closed this issue · 0 comments
flo-wolf commented
I noticed that this simple snippet produces errors when CreateWrappingSequence()
is called again while the Sequence still runs:
private Sequence _innerSequence;
public void CreateWrappingSequence()
{
Sequence wrappingSequence = Sequence.Create();
wrappingSequence.Chain(GetInnerSequence());
}
private Sequence GetInnerSequence()
{
if (_innerSequence.isAlive)
{
_innerSequence.Stop();
Debug.Log("Stopping inner sequence that still runs");
}
Sequence innerSequence = Sequence.Create();
// some tween that runs for three seconds
innerSequence.Chain(Tween.Custom(0, 1, 3, (t) => { }));
_innerSequence = innerSequence;
return innerSequence;
}
The following error appears for the Sequence innerSequence = Sequence.Create()
line:
When a tween or sequence is added to another sequence, they become 'nested', and manipulating them directly is no longer allowed.
Use Stop()/Complete()/isPaused/timeScale/elapsedTime/etc. of their parent Sequence instead.
When I remove the _innerSequence = innerSequence;
line, the error disappears. Why is this the case? _innerSequence
is a value type, and the creation of a new Sequence should not be a problem here. I should be able to just stop the current sequence and create a new one here.
Why am I even stopping the sequence? Because I want to prevent callbacks from being executed from the ongoing sequence (the code above is just a test-case to showcase the problem, my actual use case is more complex)