Firstly, I have no idea if I’m posting this in the right place, mixed feeling on this new discussions set up.
But anyway I’m looking for a little guidance regarding the implementation of my Inventory System and more specifically storing the list of items in not only the players inventory but all the NPC.
My game is a trading game, so every NPC will have their own inventories, these are grids of varying sizes and shapes. Each inventory holds multiple items, obviously, also of different sizes and shapes.
The data for each item and inventory is held in a scriptable object, then spawned as necessary. That all works just fine, as does moving items between inventories ect. I hold the scriptable objects for the items in a dictionary and each inventory can spawn them as required.
But I’m now at the stage where I want to write the starting inventory for every NPC and look at saving the players own inventory.
I had planned on attaching a list of structs to each NPC. Each struct just holding an x and y co ordinate and the key for the held item. But now that I come to implement it, it is far more fiddley than I had anticipated.
There are going to be over a hundred NPC’s so I don’t really want to have to hard code very one of their initial inventory lists, but can’t come up with a solution that lets me construct them in the inspector like I do with my item and inventory SO’s.
I’m hoping there is an easy solution I am missing
Thanks in advance for any help
If you want to actually edit a grid-like inventory as they would be displayed in the game, then you would need to implement some custom inspector tooling for this.
Or you can devise some way for a grid-like inventory to be represented one-dimensionally to make it easier to set up in the inspector. Though any project with inventory management is going to require some degree of custom inspector and editor tooling to make it possible.
I will say, think about your save games sooner rather than later. It bears mentioning that you cannot serialise Unity objects or references to Unity objects to disk. You will always need to devise a workaround for that.
Thanks,
I’ve never touched inspector editing, always been a little intimidated by the prospect actually. But it may be time to learn.
Also on the topic of saving the game. A list of structs will work for that won’t it. Creating the list and populating the inventory from it was actually really easy.
I guess what I need is a visual way to create each inventory, then to convert that into the list of structs.
Well I’m off to learn about inspector editing
Reading your post again, yeah if it’s the position and key for the item to look it up again, then that should work.
You can also design it be an indirect-reference to the item. Ergo a wrapper object that stores the key, and can be used to retrieve the item (caching it for later use). Though this generally requires some kind of global access to your item database. But it can save you having to convert the saveable data to runtime data and back again.
It can be, and there is a fairly large basis of information to learn before you can consider yourself comfortable in the subject. But I can’t stress how useful it is to be able to develop your own editor tools.
Unfortunately I don’t know any good starting resources. I kinda learnt it by the seat of my pants. A quick look on youtube shows a number of series folk’s have made, so, hopefully one of those is decent.
This is not a bad idea, and the conversion can perhaps happen at runtime. Ergo, your editor designed, initial inventory gets converted into a saveable data format the first time the player interacts with an NPC (or however it may work).