Should I use an Array List of not?

Hi,

I am making a game where the player can switch between magic spells to use as projectiles, the controls are similar to a lot of FPS games, where one can switch from weapon to weapon.

So far I have been declaring my game objects in a constructor, and setting a spell active when switching should take place. It is a successful way of achieving what I am wanting to achieve, however I am aware of Array Lists and how they are probably more appropriate for my needs than my current set up.

Please could someone enlighten me about why an Array List could be better for my needs apart from nicer looking code (the examples I can find do look nicer). I do not really get why I should use an Array, but I am open to using one at this stage.

Thanks for the prospective feedback.

Never use ArrayList
http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type
Use Array or List
As for which to use, just use which ever works for you, worry about optimization later

1 Like

Honestly, you can use List pretty much anywhere - it’s a nice wrapper around an Array which gives you the conveniece of being able to add or remove stuff. You’ll have to work with arrays for a bunch of built-in classes that uses them (like the Mesh class), but otherwise it’s not really going to matter that much.

Stay clear of ArrayList, as untyped collections are going to lead to tons of headache.

2 Likes