I am not sure if anyone knows or has done some benchmarking, but say I want to slide an object from position A to position B - is an animation more efficient, or is a script doing linear interpolation between the two points as efficient? Are there other, more efficient ways todo this?
In any answer, would the same apply for iOS targets?
P.s. If nobody knows I think I'll benchmark for iOS and post my results
I'd say that animation is faster as it is 1 line of code, and not multiple... But then again, you're calling a whole part of a file, so I don't know...
Yeah I would agree with Justin, as animation would just be reading values to set the transform instead of calculating it.
I tried both in my program and the animation looked smoother to me. That said, I may have had a flawed script and would like if you benchmarked it for the iOS and posted the results.
I asked a question like this before, and just got a bunch of annoying responses telling me to perform tests. I suggest you just post your test results and mark this as answered. Any information would be helpful; taking time to test for best practice on everything is not something some of us care to do; I'd rather be told what to do by someone I trust, so I can actually make games, instead. If I ever happened to come across contradictory results, oh well. I'll accept that possibility in exchange for the time I gain by not testing. :-P
Yep, it's a tricky one. It feels like the animation should be faster as it's fired and the native code can handle it - but how heavy weight is the native code? More so than my C# compiled into native code?
Given that lots of things are working, testing this out might need to wait until I do some re-factoring to make some of the code more production grade, but I'll post the results as an answer for iOS, probably be tested on 3G S.
Answer by Bovine
Jul 17, 2012 at 06:22 PM
So, I'm going to answer this in a slightly dubious way...
We have a tile based dungeon crawler (see link in my bio for a video, coroutines used in this vid) and we were using a Coroutine to move the player from tile to tile but I've now changed this to an animation. I made this change this for a couple of reasons:
The coroutines were messy and our controller was quite messy as a result - now much cleaner
The animations just run and our controller only has to setup the animation and wait for an animation event
Using an animation makes it easy for us to add a little bobbing up and down as the player moves from tile to tile (not yet added)
Coroutines are quite tough to save tbh...
it certainly feels faster, the animations are much more flexible and I would hope that the fact a script isn't being called every frame to martial the movement, that it's all event driven, means that it is faster.
I didn't benchmark this in a terribly scientific way, I had made the change mostly because of point 4 tbh and in doing it, the code became SO much cleaner to read, that it was worth it, provided that performance was acceptable.
We have a test LOD scene with 30 NPCs running around, sometimes all of them are in view, but either way, they are all always moving and it runs fine on 3G S and above. Animation time looking like being a typical 3MS, quite acceptable for this level of animation, including animating 7 skinned meshes as well.
Note that my answer is slightly dubious because I am saying it seems faster and it is certainly fast enough for our needs, but possibly as important is the ease of use of animations and how it helps to clean up and simplify the code.
Note that we limit the number of skinned NPCs to 5, 2 skinned meshes for the player arms. Our LOD system swaps the skinned mesh to a simple low-poly mesh fthat just bobs about. It's surprisingly effective and quite hard to spot that only 5 mobs are skinned and the rest are not.... anyway that's an aside.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
1 Person is following this question.
Hope this One is Easy
Animating 2D sprite upon movement script help.
On collide animate
2D Sidescroller: Change camera position?
GetComponent on iOS?