Using iTween ValueTo with onupdateparams

I have hundreds of objects (not GameObjects) and I need to interpolate some values on them. Instead of making them separate GameObjects, I would definitely prefer keeping their classes as lightweight as possible.

The problem with ValueTo is, I need to send an object reference to onupdate and I totally agree that iTween should also send the interpolation value to onupdate as well :). But there is an inconsistency since iTween seems to use onupdateparams parameter internally to hold the interpolation value and overwrites what we have given when creating the tween.

I can't find any examples around that uses ValueTo with onupdateparams, even in iTween's Callbacks Example and ValueTo Example.

With the solution prevented by karsten here, you only need to change 3 lines of code in iTween, and can then use an inline delegate for “onupdate”/“oncomplete”/“onstart” (instead of an explicit function) to execute arbitrary code with any parameters you like.

So for example you could then do something like:

        string colorToChange="_Color";
        iTween.ValueTo(gameObject, iTween.Hash(
            "from", a,
            "to", b,
            "onupdate", (Action<object>) (newVal => {
                Debug.Log("running iTween onupdate for "+colorToChange+" "+(float)newVal);

Just like you said in your original question, the onupdateparams are handled internally by the iTween API. I have to agree with you it’s a bit vague on how to utilize and set your value from the onupdate callback method, so I’ll give you a straight example and hopefully you can extrapolate what you need.

public float fromValue = 0;

private IEnumerator valueToExample()
     iTween.ValueTo( "from", fromValue, "to", 10, "onupdatetarget", gameObject, "onupdate", updateFromValue, "time", 5, "easetype", iTween.EaseType.easeOutExpo );

public void updateFromValue( float newValue )
     fromValue = newValue;
     Debug.Log( "My Value that is tweening: " + fromValue );