HOTween OnComplete(MyFunction) not being triggered

Viewed 1640

I have this code:

void FunctionName( Vector3 pos, Vector3 targetPos){

    Vector3[] path = new Vector3[] { 
       pos, 
       new Vector3(targetPosition.x, ((directionDown) ? 100 : -300), 0), 
       new Vector3(targetPosition.x, targetPosition.y + ( ( directionDown ) ? 300 : -500 ), 0) 
    };

    Transform starEffect = starEffectObject.transform;
    starEffect.localPosition = pos;

    HOTween.To(starEffect, 
               1.5f, 
               new TweenParms()
                   .Prop(
                       "localPosition", 
                       new PlugVector3Path(path, EaseType.Linear, true)
                   )
                   .OnComplete(TriggerFunction)
    );
}

private void TriggerFunction() {
    Debug.Log("asd");
}

My issue is that OnComplete(TriggerFunction) is not triggered as indicated in the HOTween documentation

However, if I replace OnComplete(TriggerFunction) with OnStart(TriggerFunction), everything works fine.

Can someone please assist me with this issue? Or please send me in the right direction for an alternate solution to achieving the trigger of the TriggerFunction at the end of the tween.

Thanks!

UPDATE:

I manage to trick it with:

StartCoroutine(TriggerFunction(0.2f));

IEnumerator TriggerFunction(float delay) {
    yield return new WaitForSeconds(delay);
    Debug.Log("asd");
}

But I feel like there is a better cleaner solution for doing this.

2 Answers

I haven't used HOTween, but judging from the documentation it seems to be looking for a function with a different signature.

when you call

.OnComplete(TriggerFunction)

it is likely looking for a callback function with no parameters private void TriggerFunction()

If you were to call .OnComplete(TriggerFunction, 1,2,3) then you could use the function with the single parameter private void TriggerFunction(TweenEvent data)

After reading the comment thread I believe the asset OP was using which came up bundled with HOTween must have its issues which blocked the OnComplete from callback.

it looks like I was using an outdated version of HOTween that came with another package I was using. After updating it everything works like a charm.

As I have imported HOTween in Unity2018.2 from asset store and tested the OnComplete callback still works so the issue is because of outdated/modified HOTween plugin which OP was using.

Related