Crafting System
- Lewis Bailey

- Feb 11, 2024
- 3 min read
Physically based crafting system requiring your to place items onto the crafting table and select a recipe from the book that you would like to craft.
Required Packages
How To Use
Main Scripts
Crafting Book
When the game starts it will go through all the recipes in the [`Item List`](crafting-system.md#so\_itemlist) and add a button to the crafting book with all the appropriate information using the function `SetInfo`.
Book Settings
Item List
This is a reference to the Scriptable Object which holds the data for recipes you can craft.
Item Template
This is a reference to the button which will instantiate when the game starts, so that it displays the correct information.
Book Pages
This is a reference to the pages, so it knows where to spawn the buttons for crafting different items.
Crafting Table
In `Update` it checks to see if the player is pressing E which is only to test the recipes, this can be switched out in your game to something else depending on how your player interacts with the crafting. This calls the function `Craft` which then crafts the selected item. In the function `Craft` it checks to see if you have selected a recipe if you haven't it will just not do anything. But if you have it will then wait for the time given from the recipe, and after that time, it will then craft the item requested, if you have all the correct items.
Crafting Table Settings
Placed Items Area
This is the area in which items need to be placed to allow you to craft, the size of this area can be increased and decreased. Defaults are 1,0.6,2.
Item List
A reference to the item list of craftable items.
Item Spawn Point
Where the item that's crafted will spawn.
Items Mask
Will only detect items with this mask
Scriptable Objects
SO_ItemList
This scriptable object holds the data for all of the items and item recipes that can be crafted.
All Items
Holds all the possible items that can be in the game.
All Recipes
This is all the recipes that are in the game, that can be used by the player.
Learnt Recipes
This is just a placeholder for a idea what you could add. As you could add a way to learn recipes and only display those and let the player craft only learnt recipes.
SO_CraftingRecipe
This scriptable object holds the data for the item recipe.
Item To Craft
This is the item that will be made when the crafting has taken place after the time given.
Number Of Items Produced
This is how many of a certain item will be made.
Items Needed
A list of all the required items needed to make the selected item.
Time To Craft
How long it takes to craft this item. This could be linked up to UI to show how long it has left before finishing the crafting.
SO_Items
This holds the data for the items in the game.
Item Name
This is just the name for the current item.
Item Picture
The item picture that could show in the inventory or to show what item your about to craft.
Type
The type of item about to craft, as displayed in `Item Type`
Is Cookable
This allows items to be cookable, for instance if you added a cooking system in and wanted certain items to be cooked in order to get other items.
Item Prefab
The item prefab that you want to be linked to this specific item.
Other Scripts
Set Item Button
This script is in charge of setting the correct information on the corresponding button, so it displays the right information, and when clicked sets the correct recipe to craft.
Item Type
This is just a class that holds a enum to determine the different types of items. This could be changed in the future to hold more or less depending on your use case.
Item Holder
This just goes onto item prefabs to hold the Scriptable Objects data for the specific item.
Comments