Find GameObject with value within script

Hoping to get some help here, I may be doing things a little backward and still new to Unity

I have GameObjects that are instantiated with pre-assigned unique ID values in an attached script and then have a menu open for each GameObject when requested (double click said object). I can get the values from the GameObject just fine to display but i’m having a hard time understanding how to assign values back to the unique ID GameObject.

I was reading maybe doing a search for all GameObjects into an array and then searching for said unique ID inside their attached script?

I’m working in 2D if that helps at all

If you want it to be a little more efficient than a GameObject.Find() you can store all instantiated items in a list or an array and create a search function to find the one you want.

using System.Collections.Generic;


List<GameObject> objectList = new List<GameObject>();

void InstantiateObject() {
    GameObject go = Instantiate(myObject) as GameObject;

GameObject FindObjectByID(string ID) {
    GameObject result = null;
    for (int i = 0; i < objectList.Count; i++) {
        if (objectList*.GetComponent<(your class)>().id == ID) {*

result = objectList*;*
return result;
If you’re not working with a ton of objects, a tag or name GameObject search will be fine. This just reduces the amount of items you have to sift through to find the one you’re trying to find.
If you’re working with very few items, you can store instantiated objects to global variables the same way.

You can use a Dictionary of GameObjects with id as the key.

Dictionary<int, GameObject> objects = new Dictionary<int, GameObject>();
int nextObjectId = 0;

public void AddObject()
	objects.Add(nextObjectId, new GameObject(nextObjectId.ToString()));

public GameObject GetObjectWithId(int id) {
	if (objects.ContainsKey(id)) {
		return objects[id];
	Debug.LogWarningFormat("Object with id: {0} doesn't exist!", id);
	return null;