- Home /
Get list of instantiated objects?
Hello, I'm using ARcore to spawn prefabs on detectedplanes. The prefabs overlap eachother and thats okay. When a certain number of them reach a certain concentration, I'd like to coalesce them into a different prefab, placed on that detectedplane, somewhere in the middle of the group.
My thinking is, if I had a list of these instantiated prefabs, and if I could calculate the distances between their closest neighbors, I could know the concentration.
So I need help on two things.
How to get a list of existing prefabs to calculate distances between eachother
How to destroy prefabs.
There is no tapping of the screen, my users will not be selecting individual prefabs. Anyone able to help out?
Answer by DankDev22 · Jun 04, 2020 at 12:50 AM
The instantiate method actually returns the reference to the instantiated object. You would want to do something like this:
List<GameObject> list = new List<GameObject>();
void Update(){
//code that instantites the object
list.Add(Instantiate(myPrefab));
}
the you could use nested for loops to check each GameObject and see if they are close enough to preform an action.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000030im_/https://answers.unity.com/themes/thub/images/avi.jpg)