Looting a Chest with multiple gameobjects

Hello All,

This is probably something simple or I may be staring at the screen to long but I cant quite seem to figure it out.

In the most basic terms I have my player game object and a chest gameobject to the player to loot. The chest is a prefab with an array of gameobjects, mana pot, health pot, etc that they player could loot. Its declared as a public array with a script on the chest gameobject:

 public GameObject[] chestContents;

And I can go through and drag/drop items, etc and do a loop to make sure the contents are correct:

  for (int i = 0; i < chestContents.Length; i++)
            Debug.Log("Item number is " + i + " is named " + chestContents*.name);*

What I am trying to do is when the player enters the chest collider and Hits E to loot, to Debug.Log the contents.
Right now the issue I am having is accessing the public array from my chest gameobject from my player gameobject script. I am trying to get the array Length, names, etc. No matter what I try the length is always 1 and the item names dont populate. I feel I am not accessing it publicly correct somehow. What am I missing?
here is some of my code on my player script, he kneels down to open the chest and animates the chest open, which is all working OK.
public GameObject[] swordChestList;
public int swordListLength;
void OnTriggerStay(Collider col)

if (col.gameObject.tag == “sword_chest” && Input.GetKeyDown(KeyCode.E))
Debug.Log(“Opening Chest”);
swordChestList = GameObject.FindGameObjectsWithTag(“sword_chest”);
swordListLength = swordChestList.Length;

Any help would be much appreciated. I have access other gameobjects before and chidren of objects with scripting before, so I am missing something.
If there is a better way to do this I am welcome to changes. I have tried Lists, but had almost the same results. Thanks!

While @quentionLG had a very good answer and it seems its the solution I would like to explain something that I see that could help you out very much and in my opinion on of the strongest uses of OOP, you’re going about the problem a little wrong since you’re going to have to first generate your game object that you will put in your chest, (specifically because its a game object type, you don’t have access to gameobject.itemType = sword, etc.) plus other problems that I won’t bore you with here.

What you want to do is create a class of items:

public class Item{
    public string name; //sword, staff, etc
    public float damage;
    public int weight; 
    public float sellPrice;
   //Create a constructor to handle the creation.

public class Chest{
    List<Item> listOfItems = new List<Item>();
    //An array would also work but with an array you need to initialize it's size, Lists are re sizable.
    int spaceInChest  = 10;
    public void AddToChest(Item item)
         if(spaceInChest <10)

    public void RemoveFromChest()...
    public void UnlockChest()...

//Create a item and a chest then add the item to the chest with the above classes. 
Item someItem = new Item();
Chest someChest = new Chest();

Does this make sense? This is the most important (In my opinion) thing in OOP, this saves you time and allows you to create a class exactly how you need to instead of doing all this backwards work trying to add properties to a gameObject.