Im trying to make a little inventory system but the copy of an object keeps being null

void OnTriggerEnter(Collider other)
{
if (other.tag == “Item”)
{
AddItem(other.gameObject);
}
}

void AddItem(GameObject item)
{
    string databaseItem = ("/" + "ItemDatabase" + "/" + item.name);
    item_copy = GameObject.Find(databaseItem);
    print(item_copy);
    print(item.name);
    item.SetActive(false);
}

I have an OnTriggerEnter() function that calls this when an object with the tag “Item” goes inside the player’s pick up radius.

In the first line i am making a string to put into the .Find which is supposed to look inside the empty gameobject titled “ItemDatabase” and then the look for the item that shares the same title with the picked up item.

However, this is where i run into a problem, when i print the item.name it prints out the name, but when i print out item copy, it prints out “Null” and im not sure what is going on here. (I have also tried to do item_copy.name, that causes another problem)

The issue is arising because you do not find the object. You can print out the name of ‘item’ because that is the parameter that is passed in.

 void AddItem(GameObject item) // item as parameter
 {
     string databaseItem = ("/" + "ItemDatabase" + "/" + item.name);
     item_copy = GameObject.Find(databaseItem); // it never find this object
     print(item_copy); // therefore this is 'null'
     print(item.name); // we can print the name of the parameter
     item.SetActive(false); // here we can refer to the paramter without issue
 }

I would think that you are somehow looking for the wrong object. Try to include:

print(databaseItem); // so we can determine what exactly you're looking for