Forum rules - please read before posting.

Inventory item icons always loaded in memory?

Hi. I was profiling the memory consumption of my game and realized that every inventory item's icon was always loaded in memory. Even if the item would not be granted to the player until much later in a different scene. Is that an AC setting that I can toggle? Or how can I prevent that? I'm using AC 1.74.2 and Unity 2022.3.39f1

Comments

  • As of v1.76.1, AC makes it possible to use scripting to override an item's texture at runtime via its ItemInstance. One approach would be to leave the icons fields empty, and then assign them separately at runtime via e.g. Resources:

    In earlier releases, you can still use scripting to affect the original items - but you'll have to affect the Inventory Manager asset itself, which will need resetting once you exit the game so as to avoid persistent changes.

    void AssignTexture (InvItem item)
    {
        if (item.id == 0)
            item.tex = Resources.Load<Texture> ("Item_Hat");
        else if (item.id == 1)
            item.tex = Resources.Load<Texture> ("Item_Keys");
        // etc
    }
    
    void ClearTextures ()
    {
        foreach (var item in KickStarter.inventoryManager.items)
            item.tex = null;
    }
    

    The main challenge is to set the textures at the correct time. You could try to do so at the point of addition (i.e. via the OnInventoryAdd custom event), but - at least to begin with - a brute-force approach would be to check the textures of carried items in an Update loop, i.e.:

    void Update ()
    {
        foreach (var item in KickStarter.runtimeInventory.localItems)
        {
            if (item.tex == null)
            {
                AssignTexture (item);
            }
        }
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.