Access a specific gameobject or clone

Hello All,

in my unity script I want to generate different gameobject and clones of gameobject but I want to identify every object with a specific Id maybe as tag or name.

So when I received an event from a tcp client holding an id, i want to destroy this one specific gameObject or clone with the id that was passed. Thats why I have to identify this objects globally.

Hope you can help me and show a small example, cause I think this code won’t be so much.
I am new in Unity.

Thak you very much for your help!

Just make a script to store references to what you created in a Dictionary, perhaps this:

Dictionary<int,GameObject> CreatedObjects = new Dictionary<int,GameObject>();

Make sure that callback is on the main thread or it won’t work with any of the Unity API (such as Destroy).

Delegate queue to marshal tasks from other threads to the main thread:

https://discussions.unity.com/t/850153/2