Project Information


Crafting System

This was my second crafting sytem I made, the first one I started a few days ago and it was a really rough version of this. I started it out as a project to see how far I could go without thinking it through and that really teaches me. It just had the basics, with a lot of bugs, I also spend too much time on making UI and I also worked pretty inefficient, by not making prefabs of items and slots. So after I had reached my goal for this first crafting system I wanted to remake it with documentation and thinking things through.

This crafting system also has an built in inventory system, else you wouldn't be able to click your items from somewhere and receive an item when crafting.

Going into this I quickly noticed a few challenges ahead, one of them was how I would be able to know if 2 items were able to make something, but that was resolved on the spot as I thought that I could just make a list of item recipes. Another problem was actually getting the item back in the inventory, as I didn't keep track of the slots I had and just like that didn't know if a slot contained an item.

Thinking back I could have done a few things different, like making it less dependent on other scripts or giving more feedback on screen by actually seeing an item following the mouse, but that is a lesson learned for the future.

Pictures


This is the UML I made for the system. I did stray a bit off from the UML, but I am satisfied with the results.

This is the item database that I made, here you put in a sprite, an ID number and a name and a description.

Here you can see the crafting recipes, I use the ID's of 2 items that will result in another ID that is an item.

Here you can see what the inventory looks like.

This is how it looks when there is a item combination inside the slots that actually makes something, the craft button will become interactable.

This is how it looks when played. You can't craft when the combination of items isn't correct, order does not matter.

Here you see something being crafted and put inside the inventory.

Code


I will show of a few bits of code, that I am happy with.

Click the button to see my code snippets in Git Gist!

Git gist

This is the crafting recipe script, here you can see how I chose to make the crafting work.

This is the crafting manager, here is everything that has to do with crafting, like no result or a result and if you can craft or not.

The craft result will show what item you will get or if you don't get an item.

The selection manager makes items go from slot to slot.