Created objects in List being deallocated

Hi,

I have a List

public List<VC_VirtualGood> wonVirtualGoodsList = new List<VC_VirtualGood>();

I’m adding non-Monobehavior objects to that List with a custom constructor

wonVirtualGoodsList.Add(new VC_VirtualGood(entry["shortCode"], entry["tag"], entry["name"]));

My issue is that in the next function, the list only contains null entries. So I assume the objects were deallocated by GC. Any idea how I can fix this?

If they show null, it’s because they don’t point to anything anymore. Usually it’s because it’s not in the same scope, so something that was accessible in the function, isn’t accessible outside it. That’s assuming it wasn’t null inside the function.

EDIT: My mistake! The call

new VC_VirtualGood(entry["shortCode"], entry["tag"], entry["name"])

returns null.

But I don’t understand why?

public VC_VirtualGood(string shortCodeToSet, string tag, string nameToSet) {
      
        shortCode = shortCodeToSet;

        switch (tag) {
            case "BANNER_BG":
                type = virtalGoodType.banner;
                break;
            case "BANNER_LOGO":
                type = virtalGoodType.logo;
                break;
        }

        vgTextureAsset = VC_SceneManager.Instance.loadoutManager.getTextureFromAssetBundle(shortCodeToSet, type);

        vgName = nameToSet;

    }

Nevermind, got it worked out - my custom class was still inheriting from Monobehaviour