Monday, April 19, 2010

Unity Built-in Array Woes

Like any sane programmer, I try to keep a reasonable memory footprint for anything I'm coding. So, like any sane programmer, I write everything in Assembly. No, but seriously, poor performance can ruin any good project.

I've recently begun working on a small game using the Unity game engine. One thing I've noticed is that some of the documentation seems to be a bit behind the latest version of the engine (at least for the Javascript function). One great example being the lightning fast built-in array type.

If you are doing anything that targets the iPhone or lower-end hardware, javascript arrays and hashtables can cripple your program. So, like any responsible programmer, you looked up Which Kind of Array or Collection Should I Use?, tried the built-in type for your Javascript:
var enemies = GameObject[16];

and got an error similar to:
Type 'System.Type' does not support slicing.

I've tried every version of that, but no luck. This *seems* to work:
var enemies : System.Array = System.Array.CreateInstance( GameObject, 16 );

Not quit as elegant, but it works.
Please let me know if any of you figured out a simpler way.

No comments:

Post a Comment