【Unity】DOTWeenのエラー「Tween startup failed (NULL target/property – Single xxx()): the tween will now be killed Index was outside the bounds of the array.」


DotweenのSequenceに動的にアニメーションを追加しようとして以下のようなコードを記述した。
配列parameterIdsの各要素の持つValueを0.5秒かけてToValueの値に変更したかった。

        Sequence seq = DOTween.Sequence();
        for (int paramCnt = 0; paramCnt < parameterIds.Length;paramCnt++)
        {
            seq.Append(DOTween.To(
                () => parameterIds[paramCnt].Value, 
                (n) => parameterIds[paramCnt] = n, parameterIds[paramCnt].ToValue, 0.5f));
        }
        seq.Play();

すると以下のようなエラーが発生

DOTWEEN ► Tween startup failed (NULL target/property - Single <xxxx>xxxx()): the tween will now be killed ► Index was outside the bounds of the array.
UnityEngine.Debug:LogWarning(Object)
DG.Tweening.Core.Debugger:LogWarning(Object, Tween) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/Debugger.cs:46)
DG.Tweening.Tweener:DoStartup(TweenerCore`3) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tweener.cs:138)
DG.Tweening.Core.TweenerCore`3:Startup() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenerCore.cs:230)
DG.Tweening.Tween:DoGoto(Tween, Single, Int32, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:202)
DG.Tweening.Core.TweenManager:Goto(Tween, Single, Boolean, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:708)
DG.Tweening.Sequence:ApplyInternalCycle(Sequence, Single, Single, UpdateMode, Boolean, Boolean, Boolean) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:331)
DG.Tweening.Sequence:DoApplyTween(Sequence, Single, Int32, Int32, Boolean, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:239)
DG.Tweening.Sequence:ApplyTween(Single, Int32, Int32, Boolean, UpdateMode, UpdateNotice) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Sequence.cs:143)
DG.Tweening.Tween:DoGoto(Tween, Single, Int32, UpdateMode) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Tween.cs:260)
DG.Tweening.Core.TweenManager:Update(UpdateType, Single, Single) (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/TweenManager.cs:490)
DG.Tweening.Core.DOTweenComponent:Update() (at D:/DG/_Develop/__UNITY3_CLASSES/_Holoville/__DOTween/_DOTween.Assembly/DOTween/Core/DOTweenComponent.cs:74)

以下のようにするとエラーが無事動いた。
添え字の値をスコープの外で使おうとしておかしくなってただけみたいですね。

        Sequence seq = DOTween.Sequence();
        for (int paramCnt = 0; paramCnt < parameterIds.Length; paramCnt++)
        {

            string tmpId = parameterIds[paramCnt];
            seq.Join(DOTween.To(
                () => parameterIds[paramCnt].Value,
                (n) => parameterIds[paramCnt].Value = n,parameterIds[paramCnt].ToValue, 0.5f));
        }
        seq.Play();

あわせて読みたい