I know how to drag multiple objects, but I need to drag several copies of one object. I don’t think it’s possible but I figured I should just ask. Does anyone have any insight on this?
You can drag the same object into an array multiple times, if that’s what you are asking?
This will just create an array of N x object01, which has no benefit over an array with 1 x object01.
However, if you are doing something like adding 3 different objects into an array and want the probability of any one surfacing at random more than the others, then you can drag one instance of 2 objects in and drag the 3rd one in multiple times. You could end up with an array of 10 objects which will look like:
0: object01
1: object02
2: object03
3: object03
4: object03
5: object03
6: object03
7: object03
8: object03
9: object03
Hi yes to clarify I do mean through the inspector.
@swanne I have a prefab object in one of my project asset folders and I need several of it in an array in the inspector – however I don’t want to make copies of it in the scene.
So it would be
0: prefab 1
1: prefab 2
2: prefab 3
3: prefab 3
4: prefab 3
5: prefab 3
6: prefab 3 (etc)
FYI adding the prefab from assets into an array in the inspector 60 times while technically you can do it what it means is that you are actually creating 60 references to the same prefab and not any gameobjects, any changes done on that prefab will filter to all other objects in the list and the prefab will be changed. Its like editing the prefab directly.
If that is the behaviour you want then yes just drag it 60 times. Otherwise you need to instantiate the prefab to create the copies
//Put your prefab here
public GameObject prefabGO;
//This will hold all the copies
public GameObject[] gameObjectArray;
//The number of copies you want set in inspector
public int numOfCopies;
void Start()
{
gameObjectArray = new GameObject[numOfCopies];
for (int i = 0; i < numOfCopies; i++)
{
gameObjectArray *= Instantiate(prefabGO);*
}
}