Question by
AustinJ360 · Mar 07, 2016 at 03:18 AM ·
objectpooling
Instantiate GameObject Error I dont know whats wrong with it seems right to me
void Start(){ pooledObjects = new List();
for (int i = 0; i < pooledAmount; i++)
{
GameObject obj = (GameObject)Instantiate(pooledObjects);
obj.SetActive(false);
pooledObjects.Add(obj);
}
}
My Error: says like Systems.Collection.GenericSystem.Collections.Generic.List' must be convertible to UnityEngine.Object in order to use it as parameter `T' in the generic type or method
Comment
Answer by Salocin19 · Mar 07, 2016 at 04:07 AM
In this line of code, you tried to instantiate the actual list of pooled objects, versus instantiating a Unity GameObject:
GameObject obj = (GameObject)Instantiate(pooledObjects);
You can only call Instantiate on a Unity GameObject. Therefore, your code should look something like this:
void Start(){ pooledObjects = new List();
for (int i = 0; i < pooledAmount; i++)
{
GameObject obj = (GameObject)Instantiate(pooledObjects[i]);
obj.SetActive(false);
pooledObjects.Add(obj);
}
}