i need some help at finding a way to save different crafting recipes for a basic crafting system, like the Minecraft one.
I got a working Inventory with a few Arrays for Stacks, ItemClasses, the object itself (for the specific values of that item) and a reference array that has the indices of the ItemClasses Array to spawn the Items later.
Now i want to have a crafting system with… let’s say 3 ItemSlots. If i put 2-3 Items in the Slots, i want to check if this is one of my recipes.
If easy possible, it shouldnt matter in which slot what item is. So the first one could be empty and it should still work. If not, i guess it’s ok to have a specific slot that has to be filled.
My problem is that i don’t know how to make several different recipes that are checked if the player wants to craft.
I thought about making a recipe class that got the 3 Slot variables for the slots and an Outcome Variable of type object (so i could just migrate the result to my Inventory Object Array).
The 3 Variables would contain only the indices of the ItemClasses array, cause this is prefilled by me.
Than i would have an array of that class and just run though it with a loop and check if one of them matches the setup i filled in the crafting slots.
But i don’t think that is the best way. Does anyone of you brilliant people got a good idea on how to make the recipes, save them and check them? The best would be if i could switch the items in the slots and still the same recipe is used (so i don’t have to make a recipe for each possible way to place 2-3 items in the crafting slots).
I made a class of AActor in c++ with the Slots and the Result as Variables.
I made a Main_Recipe_BP of this Class and a Small_Axe_Recipe as a second BP of the first one.
Now i filled the Variables in the Axe Recipe.
I also made an array of the RecipeClass and put the Small_Axe_Recipe in it.
Now i checked if the first slot got an item in it. If yes, i get every Class of the Array and !!!Spawn it!!! to get the values of the actor. After that i compare the crafting slot values with the slots in the recipe. If they match, i spawn the result actor from my ItemClasses Array and it its result to my inventory. After that i Destroy all actors that i spawned till then.
That sounds totaly wrong. I mean, it’s working but it can’t be that i have to spawn the Actors to get them, do i? I mean the second SpawnActorFromClass for the result is needed to get an actor that i can save in my InventoryObjectArray but the first one seems wrong.
Am i missing a way to set up different recipes and check their values or is it normal that i only can check values of spawned actors? o.o
I could place all Recipes somewhere in my Level and add them to an ObjectsArray at the BeginPlay. but i don’t believe that there isnt another way to get different recipe values than having them in your level spawned somewhere.