I am trying to create an easy situation where a game can have four unique objects, created as instances of the same object. every instance will have a variable set, to a unique number (1-4).
What is the easiest way of validating the existing instances when setting the value to the newly created one, so it will be unique.
Since instances can be deleted it is not possible to validate the index or UIDs.
Do I need to store the variables to a dictonary or an array. Or is it possible to use a For Each -loop while creating the new instrance, to get the variable from the existing ones?
See attached example (in the example I use choose(1, 2, 3, 4) to set the variable to the new instance, which of course will not check for uniqueness.
(The example is just a test, I need to function in a multiplayer game, so every player will have a unique color, players will be able to leave and join, but always 1-4 players. The animations is just a different color)