Unity physics notes - 0 views
Gapless MP3 playback? - 0 views
AnimationStates allocate piles of memory - 0 views
-
I just discovered something that I wish I'd known a long time ago... Referring to AnimationStates in an update loop, such as in the following code... Code: function Update () { if (animation["idle"].weight == 1) { // do stuff } } ... allocates massive amounts of memory each update. My first iPhone game ended up using this kind of logic quite a bit to determine animation behavior, when to play what clip, with what weight, etc. etc. Turns out it was causing the garbage collector to run overtime due to the fact that each time you use an animation state in this manner, you're burning memory. On the contrary... Code: var idle : AnimationState; function Awake () { idle = animation["idle"]; } function Update () { if (idle.weight == 1) { // do stuff } } ...causes no runtime allocation. Just thought others might like to know.
-
Another way to find it out: set ENABLE_INTERNAL_PROFILER to 1 (instead of 0) in AppController.mm. Run you game on iPhone and check XCode console output. If you see "used heap" in "mono-memory" section increasing with each frame - you have temporary allocations in your scripts.
-
As a general rule, whenever you're referring to other objects or components via script on a frame-to-frame basis, its best to cache a reference to that object/component in a variable. It is both faster, and does not require repeated memory allocation. If you need to find another object by name with GameObject.Find(), try to do it only once (such as in an Awake () function) and store it in a variable for repeated use. If you're ever in doubt as to whether you're scripts are causing memory allocations every frame, build your app in xcode and choose Run > Start with Performance Tool > Activity Monitor from the pull down menus. If your app's memory usage is slowly climbing for no apparent reason, you know you have allocations occurring every frame. After about 4 mb accumulate, the garbage collector will run and you will experience a small performance hit... which is really annoying if you're making an action game! (FYI, a lot of people observe this behavior and think its memory leaks, but this is not the case - just garbage accumulating and being discarded.) My first iphone game ended up allocating a fair amount of tiny junk all the time and as such wil experience these performance hits for a couple seconds once every 2-3 minutes during play. I hope to write cleaner code and avoid it altogether in my current project - ideally garbage collection will almost never need to run in the midst of gameplay.
Zombieville USA - performance hitches - 0 views
Health Bar UI - 0 views
-
Yes, that's the way to do it. For example, this (web player). There are two textures; one for the regular graphics (using normal alpha for nice anti-aliasing) and one for the health bar (using alpha cutoff). The health bar's alpha looks like this: The non-alpha part of the texture is just a block of solid green. The code is this: Code: function Update () { renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, Screen.width, Input.mousePosition.x)); } This is much faster, easier, and less memory-using than having an array of circular textures.