Arraylist question

Hello unity Community
Im a bit new at c# programming and I have a question about the ArrayList.
Im getting these errors: Assets/Scripts/ItemCreator.cs(34,33): error CS1502: The best overloaded method match for UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments and Assets/Scripts/ItemCreator.cs(34,33): error CS1503: Argument #1’ cannot convert object' expression to type UnityEngine.Object’

Im making my list:

ArrayList myAL = new ArrayList();

Using add() to add gameobjects to the list:

myAL.Add(LargeCoin);

Using a for loop to go through the list with count. And inside the for loop is the following code:

Instantiate(myAL[cnt], _itemSpawnPointPos, Quaternion.identity);

Its in the last bit I get my error, and i think it has something to do with the accessing for the gameobjects.

Hope you can help with this noobish question:smile:
Best Regards
Qvist

It would be better to forget about ArrayList and use generic Lists instead.

–Eric

Im getting a new error now: NullReferenceException: Object reference not set to an instance of an object
ItemCreator.Start () (at Assets/Scripts/ItemCreator.cs:26)

Line 26 has the following code:

_items.Add(LargeCoin);

The new list i made looks like this:

private List<GameObject> _items;

Variables/function/etc. are private by default in C#, so you can omit the ‘private’ when declaring/defining them.

Are you assigning a reference to a List object to _items at any point? E.g.:

_items = new List<GameObject>();

Also, what does LargeCoin refer to? If it’s a reference, has it been assigned a value?

Thanks Jesse
Forgot the: _items = new List();
:smile: