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.

  1. How to get a list of existing prefabs to calculate distances between eachother
  2. How to destroy prefabs.

There is no tapping of the screen, my users will not be selecting individual prefabs.
Anyone able to help out?

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.