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?
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;
objectList.Add(go);
}
GameObject FindObjectByID(string ID) {
GameObject result = null;
for (int i = 0; i < objectList.Count; i++) {
if (objectList*.GetComponent<(your class)>().id == ID) {*
result = objectList*;* break; } } 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.