Craft without selecting recipe

CHOPJZL

New member
Hello,
In the demo player firstly select the recipe before crafting the item. How to achieve crafting without selecting recipe? Player put the materials into the craft panel, maybe with some rules of item order like minecraft, then press a craft button. An item will be crafted if its recipe meets the condition.
 
We do not have a system like that built-in. But I can give you some tips on how you could create your own.

The easiest solution, is simply to loop over all your recipes and see if you can find one that matches the exact list of recipes. That's not very performant though, especially if you have a lot of recipes and items.

Another solution is to make dictionaries of <ItemDefinition, recipes> to know all the recipes a specific item is in. We compute that in the Editor
1619770019420.png
You can do the same using the database utility functions:
Code:
var listOfDirectRecipes = InventoryDatabaseUtility.DirectItemDefinitionRecipes(m_MainManagerWindow.Database.CraftingRecipes, itemDefinition);
var listOfInherentRecipes = InventoryDatabaseUtility.InheritedItemDefinitionRecipes(m_MainManagerWindow.Database.CraftingRecipes, itemDefinition);

By precomputing that at Edit mode and serializing the result, or by computing it at the start of the game it'll save time when you'll start searching for matching recipes.


Finally the last solution would be a custom one specific to your game. If you make something like minecraft where the placement of the item matters then you'll need a custom system to know what recipe it points to. For that I would recommend you research some "search tree" algorithms that could make that performant. I'm sure there's a lot of people who have implemented something similar and shared their solutions.

I hope this helps
 
Is there a way to let some recipe to have a higher priority?
e.g.
A+B+C=X B+C+D=Y
When I put ABCD into the panel, the output should be Y.

Or maybe in this case I should add a new recipe A+B+C+D=Y?
 
That would be part of your custom craft system.
Perhaps you could order your recipes in a list of priority, or make a custom Recipe type which has a value for priority. Or perhaps you can organize it using CraftingCategories and some categories have higher priority.
Since this is not built-in, it's up to you to decide how you wish to organize your recipes.
 
Top