Hi, everybody. Write your Tweening with the right features.
And I have a question in implementation.
There are two options:
Implement abstract class and create Tween from it.
Create an ITween interface and create structures with this interface.
As a result, the second option is faster in any case, because only structures are created, but when there is a lot more, it will be necessary for each structure to implement common functions.
In the first case, when there is a minimum, everything is implemented in abstract class, but there are classes and nesting, and it is slower, because each time it will create classes.
How to be? On how many afraid of the first option?
I don’t know what you are really saying/asking honestly. But for tweening, we tend to use LeanTween. Another popular one is Dotween. Sure, we could do our own, but unless we’d write something that was feature rich and provided much better performance, we don’t see a reason to.
We have other things to focus our programming time on. No reason to reinvent the wheel with so many tweening options already available.
If by ‘structures’ you mean ‘structs’. No it won’t be much faster if you’re attempting to save heap allocations by avoiding classes. Since because you’re using an interface, when you cast the struct to said interface… it gets allocated on the heap.
Have you profiled this? Do you know it’ll be significantly slower?
I use option 1 as you can see here:
And the overhead hasn’t really been significant in my usage.
I bet if I created hundreds of tweens per frame it would start having issues. But I’m not.
Anyways, your struct approach doesn’t necessarily solve the bottleneck you’re considering.
Really at the end of the day the biggest bottleneck I’ve found is the ‘getter/setter’ reflection of the target to be tweened. Being able to dynamically access members. I’ve seen some engines implement it via delegates instead of reflection, which actually increases the object creation since delegates are again allocated on the heap.
Yesterday I ran a lot of tests. The option with “struct” does not fit, as it is difficult to expand.
I only have one problem, I add Tween classes to the List, which then call Update. (that one main class would be called from children).
And it is the “List.Add” that receives the memory allocation (~ 56 byte)
Did you bypass this somehow? I tried to use “delegate + -” instead of List, it’s even worse, first of all it takes more memory allocation, secondly it takes more CPU time.