SetDelay is appending interval between two tween Joined in sequence
I have issue where I loop through the list of transforms I want to scale them from 0 to their original scale with all tween start at same time but play after random delay but SetDelay is appending interval between two tween Joined in sequence. So all the transform tween are playing on after another.
public void AnimateBoard(Action callBack)
{
Sequence sq = DOTween.Sequence();
int count = 0;
for (int rank = 0; rank < 8; rank++)
{
for (int file = 0; file < 8; file++)
{
Transform tr = squareRenderers[file, rank].transform;
Vector3 endScale = tr.localScale;
tr.localScale = Vector3.zero;
Tween tween = tr.DOScale(endScale, 0.2f).SetDelay(UnityEngine.Random.Range(0f, 0.5f));
sq.Join(tween);
}
}
sq.Play().OnComplete(() =>
{
callBack?.Invoke();
});
}
Try sq.AppendInterval(...) after sq.Join to make the interval a part of the sequence and not part of the tween.
@Monsoonexe I don't want tweens in sequence to play one after another I want them to play at same time but with their own individual delays.
I also encountered the same problem.
public Transform[] cubes;
[Button]
public void Test1()
{
ZLog.Log("current time:" + Time.time);
var seq = DOTween.Sequence();
for (int i = 0; i < cubes.Length; i++)
{
cubes[i].transform.localScale = Vector3.one;
}
List<string> listTime = new List<string>();
for (int i = 0; i < cubes.Length; i++)
{
int index = i;
float delay = i * 0.1f;
seq.Join(cubes[i].DOScale(Vector3.zero, 3f).SetEase(Ease.Linear).SetDelay(delay).OnPlay(() =>
{
listTime.Add("playtime:" + Time.time.ToString() + " index:" + index + " delay:" + delay.ToString());
}));
}
seq.OnComplete(() =>
{
Debug.Log("Sequence item delay:\n" + string.Join("\n", listTime));
});
}
[Button]
public void Test2()
{
ZLog.Log("current time:"+Time.time);
List<string> listTime = new List<string>();
for (int i = 0; i < cubes.Length; i++)
{
cubes[i].transform.localScale = Vector3.one;
}
for (int i = 0; i < cubes.Length; i++)
{
float delay = i * 0.1f;
int index = i;
var tw = cubes[i].DOScale(Vector3.zero, 1f).SetEase(Ease.Linear).SetDelay(delay).OnPlay(() =>
{
listTime.Add("playtime:" + Time.time.ToString() + " index:" + index + " delay:" + delay.ToString());
});
if (i == cubes.Length - 1)
{
tw.OnComplete(() =>
{
Debug.Log("no Sequence :\n" + string.Join("\n", listTime));
});
}
}
}
Test1 log: current time:0.3592569 Sequence item delay: playtime:0.3863273 index:0 delay:0 playtime:0.467084 index:1 delay:0.1 playtime:0.6654764 index:2 delay:0.2 playtime:0.9675563 index:3 delay:0.3 playtime:1.366094 index:4 delay:0.4 playtime:1.866485 index:5 delay:0.5 playtime:2.466334 index:6 delay:0.6 playtime:3.166666 index:7 delay:0.7 playtime:3.966333 index:8 delay:0.8 playtime:4.866787 index:9 delay:0.9
play time delay seems to come from the previous one.
Test2 log: current time:0.2047632 no Sequence : playtime:0.2357173 index:0 delay:0 playtime:0.312906 index:1 delay:0.1 playtime:0.4155345 index:2 delay:0.2 playtime:0.5150412 index:3 delay:0.3 playtime:0.6136377 index:4 delay:0.4 playtime:0.7150743 index:5 delay:0.5 playtime:0.8150727 index:6 delay:0.6 playtime:0.9181057 index:7 delay:0.7 playtime:1.017332 index:8 delay:0.8 playtime:1.116145 index:9 delay:0.9
play time delay seems to come from the first
But can use Insert
[Button]
public void Test1_Fixed()
{
ZLog.Log("current time:" + Time.time);
var seq = DOTween.Sequence();
for (int i = 0; i < cubes.Length; i++)
{
cubes[i].transform.localScale = Vector3.one;
}
List<string> listTime = new List<string>();
for (int i = 0; i < cubes.Length; i++)
{
int index = i;
float absoluteStartTime = i * 0.1f;
seq.Insert(absoluteStartTime, cubes[i].DOScale(Vector3.zero, 1f).SetEase(Ease.Linear)
.OnPlay(() =>
{
listTime.Add($"playtime:{Time.time} index:{index} delay:{absoluteStartTime}");
})
);
}
seq.OnComplete(() =>
{
Debug.Log("Fixed Sequence:\n" + string.Join("\n", listTime));
});
}