detect unfulfilled recipe

Dahrona

Member
how do you make a recipe that doesn't meet the ingredients, when you click it, the picker pannel doesn't appear? The recipe can't be crafted when the ingredients are not met but it shouldn't be with the quantity picker pannel.
and how the way to detect unfulfilled recipe, so I can mark the item to inform that item can't be crafted in script
 

Sangemdoko

Moderator
Staff member
There is a function in the Crafting Processor called CanCraft, there are a few overloads

public bool CanCraft(CraftingRecipe recipe, IInventory inventory, int quantity = 1)
CanCraft(CraftingRecipe recipe, IInventory inventory, ListSlice<ItemInfo> selectedIngredients, int quantity = 1)

So you'll need to make a custom UI that will do something else (craft the unfulfilled item) when the processor cannot craft.

Another option is to create a custom CraftingProcessor. There you can allow the craft but return whatever you want including the unfufilled crafted item. You define the CraftingProcessor inside the Crafter component with a dropdown.

I hope that helps
 

Dahrona

Member
okay thankyou, i can disable picker pannel when recipe can't be crafted now.

but where i can put this script :

if (!m_CraftingProcessor.CanCraft(recipe, inventory, 1))
{
Color nameColor = new Color(149, 101, 77);
m_NameText.color = nameColor;
}
else
{
Color nameColor = new Color(236, 236, 236);
m_NameText.color = nameColor;
}

to change name text color recipe when the recipe can't be craft. i try to add this script in the FirstOutputRecipeView called SetValue. but it give an error
 

Attachments

  • FirstOutputRecipeView.cs
    2.2 KB · Views: 3

Sangemdoko

Moderator
Staff member
The crafting view does not know about the Crafting Processor, so of course it will give you an error.
You need to pass in the Crafting Processor reference from the CraftingMenu orPanel to the view. You can make it public on the view and assingn it from the CraftingMenu or Panel (with custom code, you'll need to replace the CraftingMenu or Panel component with your own)
OR
You add that logic in the CraftingMenu or Panel, and then write the text of the view externally
 
Top