Can I add an item to list at a specific index?

I am using an inventory asset and trying to add items to the inventory and make sure they stack if I can. Right now I have a simple proof of concept flow implemented with the asset that allows me to remove an item and then increment its count by 1, and then put it back into the inventory’s list. However, every time I do that the items in my list have their index’s changed. I.E. Item at index 0 is removed and incremented and then put back into the list. It is now no longer at index 0. So instead I keep incrementing the items that get “bumped up” to index 0. Can I put that item back into the list at index 0?

Here is a sample of my flow.

Sorry, here, I added notes to the flow for readability.

Did you try List*.add (new item)?*
Lists - Unity Learn

I believe so, I will have to go through the tutorial you linked me. There is only one “add” function in the fuzzy finder in bolt. I was going to monkey around with the “Insert List Item” function.

6178452--676527--upload_2020-8-7_0-32-33.png

I don’t know what this is you are using; what I am referring to is code, the code you write in Visual Studio. If you are using some visual scripting asset, you’re asking at the wrong place.

I am using Bolt. Which is an asset owned by Unity. Why would I not look on the Unity support forum?

Your question is script related and you are using an asset, so it’s either the Scripting or the Asset Store section, not the General Support one. :slight_smile:

Anyway, if someone is looking for an answer to that question in code, the syntax is:

listName.Insert(indexNumber, itemToAdd);

:slight_smile:

2 Likes