Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.29k stars 344 forks source link

Why there are no params for TweenCallback #661

Closed fatihforgemaster closed 8 months ago

fatihforgemaster commented 8 months ago

i just want to set data to OnComplete then i will use it inside complete method, i really just don't want to create lambda for it because of allocation. OnComplete(() => OnCompleteEvent(someObject))

just want to use it like OnComplete(OnCompleteEvent(someObject))

Demigiant commented 8 months ago

Hi,

The only other solution would be for you to store that someObject, so you won't need to pass it to the OnComplete callback and you can just pass the callback without a lambda and without allocations. Any other way I could implement would still create allocations because of boxing/unboxing (since I have no way to know what type your object is).

fatihforgemaster commented 8 months ago

Hi,

The only other solution would be for you to store that someObject, so you won't need to pass it to the OnComplete callback and you can just pass the callback without a lambda and without allocations. Any other way I could implement would still create allocations because of boxing/unboxing (since I have no way to know what type your object is).

in my test () => OnCompleteEvent(GameObject) creates 128B alloc

you should add params object[] to callback boxing/unboxing 1 GameObject just creates 40B and we can use it for more use cases

void UnBoxing(params object[] box)
{
       var b = box[0] as GameObject;
}
Demigiant commented 8 months ago

I pondered about it but there's also the issue that I cannot add a conditional callback unless I add an extra field to a tween so I can store both callbacks separately, and I think that would be more detrimental (both because I'd need to check for two callbacks instead of one and because of the added field)