Is there a way to change the label of an inventory item during gameplay? I am looking for a similar action like Rename Hotspot, but I could not find anything for the inventory.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Not without scripting - unlike Hotspots, inventory data is stored in asset files.
The easiest way around this is to create a second instance of the item - i.e. same graphic - but with a different label. You can then swap one for the other using the Inventory: Add or remove Action's "Replace" option, giving the effect of its name being changed.
Thanks! I was thinking about the same solution you mentioned, but I was curious if there is another way.
I just wanted to check if having multiple items is still the preferred way to do this?
It would be nice with something similar to hotspot.SetName("new label", lineId) if possible. But I guess the way they are stored might make this difficult.
Thanks
Changing the name directly would involve updating the raw asset data, which I don't recommend.
Technically, it is possible - right-click the item's Label (if not name) field label to get an API reference to it that can be set at runtime. Such a change will persist upon exiting Play Mode, however.
Swapping the item out for another is the safer approach.
Hi Chris, I was able to make it work by using Inventory: Add or remove for this feature. However, since I am also using OnInventoryAdd to make a menu popup everytime a new item is added to the inventory, the menu keeps popping up whenever the empty bottle is added back. Anyway to work around this? Thanks in advance.
Since the time of my last writing, it's now possible to override an item's label via the ItemLabel property.
Example usage:
I assume it's similar to change the graphic?
Yes.
Hi Chris, I am still struggling with it since I am not a programmer.
Is it ok if you can give me an example of the script? 🥲
To use it, attach to an empty GameObject, make a prefab, remove from the scene, and assign the textures in its Inpsector.
Then, use the Object: Call event Action, reference the prefab, and invoke either the ChangeItemData component's ChangeToFullBottle or ChangeToEmptyBottle functions (I'm guessing the intent here).
I think I am doing something wrong as I cannot see those functions, or maybe I am looking at the wrong place?
https://www.dropbox.com/scl/fi/3pztcemu4231ftrtglxom/Screenshot-2024-11-13-090327.png?rlkey=4iocv2v2dlo5536h385pybomf&dl=0
Maybe is because of these errors?
https://www.dropbox.com/scl/fi/57f9165to1mb54h9s4u9n/Screenshot-2024-11-13-091836.png?rlkey=poe4cgeoakbzlu96s0egfl931&dl=0
oh I fixed the errors.
Yay it worked. Thank you so much Chris. You the best! 😀
@ChrisIceBox , is there a way to make this survive scene change and saving?
I'm afraid not - at least not automatically. You would need to keep track of these changes via a separate script, and then apply them back to the items upon loading.
A tutorial on saving custom global data can be found here.
Understood. Thanks for letting me know.