Forum rules - please read before posting.

There is no "Result is automatic?" option in Recipe properties!

edited January 2021 in Technical Q&A

I want to use Create button to craft the item, add it to inventory and select it but it does it automatically and unity crushes.
There is no "Result is automatic?" option in Recipe properties in Inventory Manager.

Comments

  • Welcome to the community, @Housein.

    The Result is automatic? option is a property of the "Output" Crafting element. In the default Crafting menu, this is the "Crafting" element in its list of elements.

    If you're getting a crash without this option checked, can you share more details? What are your AC/Unity versions, and what steps are necessary to recreate this issue?

  • edited January 2021

    I don't have Output in UI. I have just ingredients, close & Create buttons. (customized Crafting UI & menu)
    I don't want it to Craft automatically. Is it possible: player put ingredients in, and click on Create button, if they met the recipe, Crafted item adds to inventory, and will be selected.
    Crush:
    it happens when I add Action:inventory/select crafted item in Recipe_OnCreate actionList. it spawns thousands of Recipe_OnCreate and unity crushes.
    the other way is to check "can carry multiple" in ingredients and final product properties

    if I don't use Select item action and uncheck "can carry multiple" for all items, it will create the final product automatically as I add the last ingredients and 3 Recipe_OnCreate will be spawned.

  • What else is in your "Recipe_Recipe1_OnCreate" ActionList, and at what moment does this list appear in your Hierarchy?

    Without an Output box, you'll need to hook into the OnCraftingSucceed custom event to manually add and select the recipe's result once the Inventory: Crafting Action is used. Placed in your scene, this should do it:

    using UnityEngine;
    using AC;
    
    public class AutoGetCrafting : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnCraftingSucceed += OnCraftingSucceed; }
        private void OnDisable () { EventManager.OnCraftingSucceed -= OnCraftingSucceed; }
    
        private void OnCraftingSucceed (Recipe recipe)
        {
            KickStarter.runtimeInventory.PerformCrafting (recipe, true);
        }
    
    }
    
  • edited January 2021

    "What else is in your "Recipe_Recipe1_OnCreate" ActionList?"

    "at what moment does this list appear in your Hierarchy?"

    as I add the last ingredient(after a second)

    it performs crafting before player try Create Button.
    and makes this error:

  • edited January 2021

    Which AC version are you using?

    The error is coming from a Crafting element of type "Output". Check your Menus - it may still be part of the original Crafting menu. Bear in mind that this will be affected even if it's not currently turned on.

    It's this element that has the "Result is automatic?" property checked. Once unchecked, the user will have to click the Create button for the recipe to be processed.

    The "ActionList on create" you've set up will not be necessary with the above code - does the error persist if you unassign this ActionList?

    If so, try opening MenuCrafting.cs and replace line around 660:

    AdvGame.RunActionListAsset (activeRecipe.actionListOnCreate);
    

    with:

    if (activeRecipe.actionListOnCreate && !KickStarter.actionListAssetManager.IsListRunning (activeRecipe.actionListOnCreate))
    {
        AdvGame.RunActionListAsset (activeRecipe.actionListOnCreate);
    }
    
  • yes I figured it out, the problem was that CreateRecipe() in PlayerMenus was looking in all menus for all crafting elements even if they were not active (don't know why).

    I didn't touch the original one so "Result is automatic?" was checked. there were two other custom menus with crafting elements. so 3 action lists called at the same time. and with Inventory: Select item in each of them the crush occurs
    I unchecked autoCraft option for all of them and problem solved.

    Which AC version are you using?

    v1.72.4

    does the error persist if you unassign this ActionList?

    No

    the new question is :grin: :
    since I don't want to use Output box in my UI. I want to press Create button,
    if ingredients are correct
    - the final product be added to the inventory
    - used ingredients removed.
    - menu clear & turn off.
    - final product item be selected.
    else
    - alert: "incorrect ingredients"
    I did all with Recipe_OnCreate ActionList but "remove used ingredients" .
    what is the best way to do it?

  • The Inventory: Crafting Action, with its Method set to Clear Recipe, will transfer all items from the "Ingredients" Crafting element back to the Player's Inventory.

    Alternatively, you can incorporate these steps into the script I provided earlier.

    using UnityEngine;
    using AC;
    
    public class AutoGetCrafting : MonoBehaviour
    {
    
        private void OnEnable () { EventManager.OnCraftingSucceed += OnCraftingSucceed; }
        private void OnDisable () { EventManager.OnCraftingSucceed -= OnCraftingSucceed; }
    
        private void OnCraftingSucceed (Recipe recipe)
        {
            KickStarter.runtimeInventory.PerformCrafting (recipe, true);
            KickStarter.runtimeInventory.RemoveRecipes ();
            PlayerMenus.GetMenuWithName ("Crafting").TurnOff (); // Replace with the Menu's name
        }
    
    }
    

    The "fail" condition is also a property of the "Output" crafting element. In the same element that you unchecked Result is automatic? for, assign an ActionList in its ActionList on fail field.

    This ActionList will be run in the event that no Recipe is possible upon clicking the "Create" button, and can be used to display "Incorrect ingredients" as e.g speech text, or by showing a previously-hidden Menu Label element with the Menu: Change state Action.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.