Lists are empty when they aren't supposed to be

I have some code that is meant to dequeue troops and queue them. When I click on the menu items, they are meant to decrease and destroy if they are smaller than 1 and they do this fine but, my lists are acting up, they seem to be empty when in debug inspector mode, they have 1 entry but it’s missing and I tried to reset that but it doesn’t work. I don’t know what to do about this and I really want to fix this. The problem is in the dequeue function. Here is my code:

using UnityEngine;
using UnityEngine.Rendering.PostProcessing;
using System;
using System.Collections.Generic;
using TMPro;

public class GameManager : Singleton<GameManager> {

    private PostProcessProfile _postProcessingProfile;
    private Vignette _vignette;

    [SerializeField] private GameObject _queueItemPrefab;
    private Transform _trainingQueue;

    private readonly int _queueMax = 5;
    private readonly int _queueNumberMax = 5;
    private List<QueueItem> _currentlyQueued;
    private List<GameObject> _currentlyQueuedItems;

    private void Awake()
    {
        _postProcessingProfile = GameObject.Find("PostProcessingVolume").GetComponent<PostProcessVolume>().profile;
        _vignette = _postProcessingProfile.GetSetting<Vignette>();
        _vignette.active = false;
        
        _trainingQueue = GameObject.Find("TrainingQueue").transform;

        _currentlyQueuedItems = new List<GameObject>();

        UpdateQueueItemLists();
    }

    public void DeQueueTroop(GameObject textObject)
	{
        TMP_Text text = textObject.GetComponent<TMP_Text>();
        GameObject parentGameObject = textObject.transform.parent.gameObject;

        if (Convert.ToInt32(text.text) <= 1)
        {
            // There's nothing in the list, Output: Count: 0
            print("Count: " + _currentlyQueuedItems.Count);
			_currentlyQueuedItems.Remove(parentGameObject);

			for (int i = 0; i < _currentlyQueuedItems.Count; i++)
            {
                UpdatePosition(_currentlyQueuedItems*, i);*

}

Destroy(parentGameObject);

UpdateQueueItemLists();
}

  •  else*
    
  •  {*
    

parentGameObject.GetComponent().DeQueue();

  •  }*
    
  • }*

public void QueueTroop(string troopType)

  • {*
    foreach (QueueItem current in _currentlyQueued)
    {
    if (Convert.ToInt32(current.GetText().text) < _queueMax)
    {
    if (current.GetUnitType() == troopType)
    {
    current.Queue();
    return;
    }
    }
    }

if (_currentlyQueuedItems.Count < _queueNumberMax)
{
GameObject queueItem = Instantiate(_queueItemPrefab, _trainingQueue, false);
UpdatePosition(queueItem, _currentlyQueuedItems.Count);

_currentlyQueuedItems.Add(queueItem);
int indexOfItem = _currentlyQueuedItems.IndexOf(queueItem);

UpdateQueueItemLists();

_currentlyQueued[indexOfItem].SetUnitType(troopType);
}
}

private void UpdateQueueItemLists()
{
if (_currentlyQueuedItems == null) return;

List old = _currentlyQueuedItems;
_currentlyQueuedItems = new List();

foreach (GameObject go in old)

  •  {*
    

if (go != null)

  •  	{*
    

_currentlyQueuedItems.Add(go);

  •  	}*
    
  •  }*
    

_currentlyQueued = new List(_currentlyQueuedItems.Count);
for (int i = 0; i < _currentlyQueuedItems.Count; i++)
{
if (currentlyQueuedItems*)
_currentlyQueued.Add(_currentlyQueuedItems.GetComponent());*

}
}_

private void UpdatePosition(GameObject go, int idx)
* {*
// Don’t touch these values! They are these because it spawns in world space and I can’t change that
go.transform.position = new Vector3(17.5f - (2 * idx), -8.5f, 0f);
* }*

}
Image of the output of the print(_allQueueItems.Count); call:
[187034-scuffedlists.png|187034]

_currentlyQueuedItems = new List(); this line of code you use doesnot populate the _currentlyQueuedItems list

I fixed the problem by just re writing the code and using arrays. Here is the code if anyone is interested:

    private void Awake()
    {
        _trainingQueue = GameObject.Find("TrainingQueue").transform;

        _currentlyQueuedItems = new QueueItem[_maxQueueItemObjects];
        for (int i = 0; i < _currentlyQueuedItems.Length; i++)
        {
            _currentlyQueuedItems *= Instantiate(GameAssets.I.QueueItemPrefab, _trainingQueue, false).GetComponent<QueueItem>();*

currentlyQueuedItems.transform.localPosition = new Vector3(430 - (i * 120), 0f, 0f);
currentlyQueuedItems*.gameObject.SetActive(false);*
}

}
public void DeQueueTroop(GameObject senderObject)
{
QueueItem item = senderObject.GetComponent();
AddCost(item.GetUnitType());

if (item.GetNumberCurrentlyQueued() <= 1)
{
item.SetUnitType(“Null”);
item.ResetNumberCurrentlyQueued();
item.gameObject.SetActive(false);
}
else
{
item.DeQueue();
}
}

public void QueueTroop(string troopType)
{
foreach (QueueItem item in _currentlyQueuedItems)
{
if (!item.gameObject.activeSelf) continue;

if (item.GetNumberCurrentlyQueued() < _queueNumberMax)
{
if (item.GetUnitType() == troopType)
{
SubtractCost(troopType);
item.Queue();
return;
}
}
}

foreach (QueueItem item in _currentlyQueuedItems)
{
if (!item.gameObject.activeSelf)
{
item.gameObject.SetActive(true);
item.ResetHazeFill();
item.Queue();
item.SetUnitType(troopType);
SubtractCost(troopType);
return;
}
}
}

private void SubtractCost(string troopType)
{
if (troopType == “Soldier”)
PlayerStats.IncrementGold(-costSoldiers);
else if (troopType == “Ship”)
PlayerStats.IncrementGold(-costShips);
else if (troopType == “Plane”)
PlayerStats.IncrementGold(-costPlanes);
}
private void AddCost(string troopType)
{
if (troopType == “Soldier”)
PlayerStats.IncrementGold(costSoldiers);
else if (troopType == “Ship”)
PlayerStats.IncrementGold(costShips);
else if (troopType == “Plane”)
PlayerStats.IncrementGold(costPlanes);
}