Forum rules - please read before posting.

Update Inventory Item Property Values

edited November 2022 in Technical Q&A

Hi everyone!

Just curious, is it possible to update property values through custom actions or existing scripts?

As an example, I have an inventory item called Ice Cream and the property value is called description.

At first, the description is "this is something with sprinkles." Further down the line, I'm hoping to update the description to "this is something with sprinkles that is yummy."

Thank you!


  • It's possible, yes. As you'll need to deal with the exact instance of the item you want to affect, though - i.e. not the original item itself - it will need to be done through script:

    InvInstance iceCreamInstance = KickStarter.runtimeInventory.PlayerInvCollection.GetFirstInstance ("Ice cream");
    if (InvInstance.IsValid (iceCreamInstance))
        iceCreamInstance.GetProperty ("Description").TextValue = "this is something with sprinkles that is yummy";

    See the Manual's "Inventory scripting" chapter for details on how to get and work with the InvInstance class.

  • Apologies for just getting back to you -- thank you so much! :)

  • @ChrisIceBox

    I'm just curious to know, might it be possible to create a custom action for this?
    The reason why I was curious is because the player has a phone with "contacts" and "notes" in which these items are actually inventory, and I am using their descriptions on the side panel (screenshot attached here).

    In the screenshot above, the inventory item is "Celestina," and the description is "My best friend since I was five."

    After a certain event fires in the game, I would like the description to be "My best friend since I was five, who has an impeccable sense of fashion."

    I'm wondering if I can create a custom action (that takes in an inventory item and a "new description") to achieve this, since there are various times through the game that descriptions would be updated.

    Also, would I have to create a remember component for this?

    Thank you so much! :)

  • As a preface: I should note that it an alternative approach would be to use the Inventory: Add or remove Action's "Replace" method to swap out the Celestina item for another (e.g. Celestina_Updated) that has the same interactions but a different property value. You'd have to make sure that Hotspots still react to it as they would the original item, but it wouldn't need any custom code.

    As for the custom Action: yes, it's possible. This should do it:

    using UnityEngine;
    using UnityEditor;
    namespace AC
        public class ActionSetInvString : Action
            public override ActionCategory Category { get { return ActionCategory.Inventory; }}
            public override string Title { get { return "Set string property"; }}
            public string itemName;
            public string propertyName;
            public string textValue;
            public override float Run ()
                InvInstance invInstance = KickStarter.runtimeInventory.PlayerInvCollection.GetFirstInstance (itemName);
                if (InvInstance.IsValid (invInstance))
                    invInstance.GetProperty (propertyName).TextValue = textValue;
                return 0f;
            #if UNITY_EDITOR
            public override void ShowGUI ()
                itemName = EditorGUILayout.TextField ("Item name:", itemName);
                propertyName = EditorGUILayout.TextField ("Property name:", propertyName);
                textValue = EditorGUILayout.TextField ("String value:", textValue);

    As Inventory items are asset-based and part of AC's core, no Remember script is necessary.

  • edited December 2022

    Thank you so much! The alternate solution sounds like a nice thing to explore, so I might look into it if the custom action is too cumbersome on my end.

    Appreciate the code snippet! :smiley: Thank you so much for writing this out!

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.