Object Association in a List


I have a List of GameObjects, some GameObjects are associated with other GameObjects and the association is stored as a List within the class.

I am trying to work out if there is a way to remove GameObjects from the list so that in the end there is only a list of GameObjects that are not associated with each other, while removing as few GameObjects as possible.

My thoughts are to start with the GameObject that has the most associations, and work on from there.

Here is an example of the GameObject associations:

GAMEOBJECT NUMBER [Other GameObjects Associated with this one]

GameObject1 [GameObject2, GameObject4, GameObject5, GameObject6]

GameObject2 [GameObject1, GameObject4]

GameObject3 [GameObject5, GameObject6]

GameObject4 [GameObject1, GameObject6]

GameObject5 [GameObject1, GameObject3]

GameObject6 [GameObject1, GameObject3, GameObject4]

GameObject7 [null]

Example of the List construction:

var listOfGameObjects = List.<CollectionOfObjects>();

class CollectionOfObjects
	var thisGameObject : GameObject;
	var associatedGameObjects = List.<GameObject>();
	var totalNumberOfAssociations : int;

Is this kind of sorting even possible? Thanks!

Unity is a Pattern Oriented.

I’d do that as follows.

1 - Create a script that will hold the list of GameObjects that will be associated with the object.

2 - Assign that script to the object and put game objects into that list.

3 - Create a controller object and assign it a controller script.

4 - In that controller script keep the list of objects with inner list of objects.

That would look like:

Controller Object[List Controller]

|-- Game Object 1[Object with associated objects 1]

|------Game Object 1a[Associated Object to 1]

|------Game Object 1b[Associated Object to 1]

|------Game Object 1c[Associated Object to 1]

|-- Game Object 2[Object with associated objects 2]

|------Game Object 2a[Associated Object to 2]

|------Game Object 2b[Associated Object to 2]

|------Game Object 2c[Associated Object to 2]

|-- Game Object 3[Object with associated objects 3]

|------Game Object 3a[Associated Object to 3]

|------Game Object 3b[Associated Object to 3]

|------Game Object 3c[Associated Object to 3]