Unity Community |

Hello,
I only saw this tip in one old topic,and wasn't very sure about how efficient it was, so I ran a test :
test 1 : assigning to a float variable the weight of an animation by calling it via this[] (ex : anim["walk"]), looping 10000 times
test 2 : assigning to a float variable the weight of an animation by calling it via an AnimationState cache (ex : AnimationState ac = anim["walk"] before running the test, then calling ac.weight during test), looping 10000 times
result :
test 1 returned a duration of 50 to 80 ms per batch of 10000 calls
test 2 returned a duration of 3 to 8 ms per batch of 10000 calls
(tested on an i7 920 intel proc)
Caching which animation clips you're calling is therefore 10 times faster.
I didn't think it would be this huge a difference, tbh, hence the creation of this topic for further reference.
Kinetic Damage, a 4 years long fighting game project : Official Trailer,
Official Site : www.kineticdamage.com, Facebook page (blog, articles, dev updates).
Dev Blog : Giant thread (+ additional tips & techniques)
thanks for sharing man, that is very cool.
Tell me about the game, is she progressing well?
About Simian Squared Recent The Other Brothers Physynth Recommended Shaders+Framework
Kinetic Damage, a 4 years long fighting game project : Official Trailer,
Official Site : www.kineticdamage.com, Facebook page (blog, articles, dev updates).
Dev Blog : Giant thread (+ additional tips & techniques)
I made another interesting test :
It seems that storing all AnimationStates inside a Dictionary gives twice faster access than with this[animName], too.
test 1 :
Code:
float test; for (int i = 0; i < 10000; i++) test = ac.weight;
test 2 :
Code:
for (int i = 0; i < 10000; i++) foreach(KeyValuePair<string, AnimationState> kvp in lib) test = kvp.Value.weight;
There are 510 animation clips inside the Animation sampled component.
test time with this[clip] : 320 ms
test time with Dictionary : 151 ms
The only cullprit is the Dictionary generation time, which was in this case : 231 ms.
So it seems like using this[animName] is absolutely not recommended at all.
edit : Additionally, storing the 510 x 2 animations (2 characters) inside the Dictionary didn't create any Memory overhead at all. So I guess that it's really a benefit to store any anim clip, even if it costs 2 seconds more at startup.
p.s : I measured the base difference between ms values on my PC and on a Galaxy S, and you can expect 10 times the duration of PC test results on the Galaxy S. So I guess 15-20 times on a 3GS, 5 times on a 4S.
Last edited by n0mad; 03-03-2012 at 10:42 AM.
Kinetic Damage, a 4 years long fighting game project : Official Trailer,
Official Site : www.kineticdamage.com, Facebook page (blog, articles, dev updates).
Dev Blog : Giant thread (+ additional tips & techniques)
Hey n0mad! Might I ask two things of you for complete clarity?
1.Can you link the original tip-thread you mention? I believe it was Mika's thread(regarding Zombieville) but I'd like to see the one you're referencing.
2. Can you post pseduo-code for the two original tests you started this thread with?
Thanks man!
-Steve
Steve Bodnar - Animation Director
FlipFrame Animation/Games
Recent Project - Bioshock Infinite
Current Project - 'Unreleased'
Hi SteveHey n0mad! Might I ask two things of you for complete clarity?
1.Can you link the original tip-thread you mention? I believe it was Mika's thread(regarding Zombieville) but I'd like to see the one you're referencing.
2. Can you post pseduo-code for the two original tests you started this thread with?
Thanks man!
-Steve
1 - I found this thread last week, so I didn't save the url, sorry :/ But yeah, I recall Mika asking similar questions for Zombieville ^^
2 - sure :
test 1 (this[myAnimName]) :
Code:
float test; for (int i = 0; i < 10000; i++)
test 2 (cached AnimationState) :
Code:
float test; for (int i = 0; i < 10000; i++) test = ac.weight;
Kinetic Damage, a 4 years long fighting game project : Official Trailer,
Official Site : www.kineticdamage.com, Facebook page (blog, articles, dev updates).
Dev Blog : Giant thread (+ additional tips & techniques)
Awesome!
Also, just in case this is what you were looking at:
http://forum.unity3d.com/threads/207...iles-of-memory
Years ago, yet it's one area inexperienced developers overlook. Significant if I may say so...
Thanks n0mad
-Steve
Steve Bodnar - Animation Director
FlipFrame Animation/Games
Recent Project - Bioshock Infinite
Current Project - 'Unreleased'
Ah yes, precisely![]()
Kinetic Damage, a 4 years long fighting game project : Official Trailer,
Official Site : www.kineticdamage.com, Facebook page (blog, articles, dev updates).
Dev Blog : Giant thread (+ additional tips & techniques)