Hi there, I wanted to share the first part of a tutorial I wrote about creating a slot-based inventory system in Unity that would sync-up in multiplayer.
[mod edit : old link removed]
If there’s enough interest I’ll post the second part soon.
I was wondering the same thing. With a list, you wouldn’t need code like this:
public int FindEmptySlot()
{
for (int i = 0; i < slotAmount; i++)
{
if (!items.ContainsKey(i))
{
return i;
}
}
return -1;
}
Plus, iterating through a dictionary is slower than iterating through a list.
Now (hopefully) that shouldn’t matter too much since this is UI code, ideally these iterators should only happen when something actually changes or updates. However… if it’s more efficient using a list, why not use a list?
Now, if you were to use a doll menu instead with specific equipment slots (left arm, right arm, torso, etc.) then it’d make sense.
Good question, guys. As it is now there really is no reason to use a dictionary, as you pointed out. The list is faster and has less overhead, as far as I know. But the reason I used a dictionary is beacuse in the next part of the tutorial we will add the ability of an item to occupy more than one slot, and the key in the dictionary will change to an InventoryPos structure.
I’ll add that info in the tutorial, thanks for pointing that out!
Even then it wouldn’t; unless your intention was to classify loot by those slots (maybe).
Not sure that this is the best way to handle that still but I’ll withhold further critique until you show the actual code. Good subject to tackle though!
I think the tutorial needs to be broken down more because you just slapped some code onto the page and I don’t really understand it. I’m sort of a noob and this really looks cool but I want to be able to understand it. What would be cool to is if you made videos explaining it too.
My Virus scanner blocked your tutorial link as a malicious virus attack, I’ve reported this post in the meantime in order for someone at Unity to take a look.