Stop the nested (inner/child) tween when the parent Sequence isAlive. #95
-
I noticed that this simple snippet produces errors when 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
When I remove the 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) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey Florian, Not allowing to manipulate nested (inner) tweens and sequences is a design decision. PrimeTween logs an error when you try to call any method or change any property of the nested animation. In your case the error comes from The reasoning behind this decision was the following: sequence is a logical union of all its nested animations that act as a whole. When you add an animation to the parent sequence, this animation becomes dependent on the parent sequence, meaning that it no longer updates itself directly. Instead, the parent sequence takes control over all its nested animations and it's no longer allowed to manipulate them directly. In your case, you probably want to store the _wrappingSequence and stop it if it's still running when the CreateWrappingSequence() is called: Sequence _wrappingSequence;
public void CreateWrappingSequence() {
if (_wrappingSequence.isAlive) {
_wrappingSequence.Stop();
}
_wrappingSequence = Sequence.Create().Chain(GetInnerSequence());
} Few other thoughts on this design decision:
var t1 = Tween.Position(transform, Vector3.one, duration: 1f);
var t2 = Tween.Rotation(transform, new Vector3(90, 0), duration: 1f);
Sequence.Create(t1).Chain(t2);
t1.Complete(); What should happen after the
|
Beta Was this translation helpful? Give feedback.
Hey Florian,
Not allowing to manipulate nested (inner) tweens and sequences is a design decision. PrimeTween logs an error when you try to call any method or change any property of the nested animation. In your case the error comes from
_innerSequence.Stop();
, not from the_innerSequence = innerSequence;
assignment.The reasoning behind this decision was the following: sequence is a logical union of all its nested animations that act as a whole. When you add an animation to the parent sequence, this animation becomes dependent on the parent sequence, meaning that it no longer updates itself directly. Instead, the parent sequence takes control over all its nested animations and it's no lon…