Keeping track of multiple instances of one prefab

I’m instantiating a small number (4 to 5 instances) of the same prefab into a single scene, the prefabs are rigidbodies and are spawned in sequence over time (with a for loop) and all appear in the inspector as “nameofprefab(Clone)”

As each instance is used for a scoring mechanism I need to be able to uniquely identifiy each one for collision purposes but am unsure of how to give each instance a unique ID.

What is the best practice for this? Is there a way I can give each instance a unique name when it’s spawned? I’ve heard of “tags” but not had the chance to read about them yet - although I’m not sure if they are the correct way of solving my problem.

Secondary to this, I also need to instantiate a blob shadow projector (for each instance) which will be told to follow it - currently I attach a script to a blob shadow projector which tells it what gameobject to follow in a pre-determined fashion, I’m a bit unsure of how to automatically instantiate multiple instances of shadow projectors which dynamically are able to follow different instances (hopefully with some kind of unique ID) of the same prefab.

I really hope this makes sense!

Can anyone help with these issues?

Show us your spawn code and we can easily add it I think.

But to explain it in short.

The line where you use the Instatiate function, keep the result in a GameObject variable. Like:

GameObject goTemp = Instantiate(something)…

Then on the goTemp object, you now how … tradaaa! .name attribute.

I usually do it like this:

for(int cnt=0; cnt<10 ; cnt++)
{
   GameObject go = Instatiate(something);
   go.name = "Something_" + cnt; 
}

To add the number in the end of the name + I am still able to search for “something_” with the GameObject.Find(“something_”) function

If the object has a script attached to it the script can access by transform in example:

void OnCollisionEnter()
{
   Destroy(transform.gameObject);
}

would destroy the object when it is collided with.

the way i track my objects is to store the reference of that object in a list of gameobjects

List myGameObjectsToTrack;

myGameObjectsToTrack.Add(thelocalGameObjectInstantiated);

myGameObjects[indexOfMyGameObjectIWouldUse].

using events and the gameobjects themselvels, would be a way to solve your issue