So I have a function that is simply searching for colliders within a radius and then I want to add the gameobjects that those colliders are attached to to a list.
The problem I am having is that each gameobject has two colliders attached, so each time my function runs each gameobject gets added to the list twice.
Can anybody give me some help or direction in best practise to find each game object but only add it to the list once?
The objects are likely to have duplicate names and tags.
Pretty easy. Don’t add the collider or colliding transform itself, but use Transform.root instead which will return itself if it already is the root.
Then you can also check with Generic Lists whether they already contain an object, so something like this will help:
Transform rootTransform = collidingTransform.root;
if (!collidingObjectsList.Contains(rootTransform)
collidingObjectsList.Add(rootTransform);