Crafting Recipe List Gamepad Input

Whenever the crafting menu opens, I'm trying to figure out the best way to have the recipe list selected so that I can use the gamepad to move up and down the list. If I hover the mouse over the recipe list, then the gamepad works fine, but I can't get the gamepad to recognize the recipe list when the crafting menu is opened. It appears to be selected, but won't work until I move the mouse first.

Any ideas?

Screen Shot 2021-05-26 at 9.56.18 PM.png
 
That's odd, I tried to replicate the issue, but it works fine for me. I double checked the code and I don't see why the slot wouldn't be selected.
What does the Event System say when you open the crafting menu?
If it worked fine it should say something like this:
1622100916880.png
 
That was helpful - it looks like the QuantityPickerPanel had MainButton set as Selectable On Open. I set that to None, which worked in getting it to select the list item first. However, when I press the main gamepad action button to select a recipe, it shows the quantity picker but doesn't transfer control over to it, whereas it did before when it wasn't starting on the list item. I'm not getting any console warnings or errors and the EventSystem is just staying on the List Button. Super strange - any ideas on this one?
 
I see... perhaps the Quantity Panel implicitly selects the main button when open, so by disabling that option nothing tells it to select that button.
Is there any reason the Quantity Panel opens before a crafting recipe is clicked? Perhaps you have an option to open on start selected?

I could change the code such that it explicitly selects the main button when the crafting recipe is clicked. It would require a few changes in those scripts:

In QuantityPicker add this function:
Code:
/// <summary>
/// Select the main Button.
/// </summary>
public void SelectMainButton()
{
    m_MainButton.Select();
}

In Crafting Menu call the function above when you click the crafting recipe:
Code:
/// <summary>
/// Recipe is clicked.
/// </summary>
/// <param name="recipe">The recipe.</param>
/// <param name="index">The index.</param>
private void CraftingRecipeClicked(CraftingRecipe recipe, int index)
{
    m_SelectedRecipe = recipe;
    m_QuantityPickerPanel.Open(m_DisplayPanel, m_CraftingRecipeGrid.GetButton(index));
    m_QuantityPickerPanel.QuantityPicker.MinQuantity = 1;
    m_QuantityPickerPanel.QuantityPicker.MaxQuantity = 2;
    m_QuantityPickerPanel.ConfirmCancelPanel.SetConfirmText("Craft");
    m_QuantityPickerPanel.QuantityPicker.SetQuantity(1);
    m_QuantityPickerPanel.QuantityPicker.SelectMainButton();
    CraftingAmountChanged(1);
}

Let me know if that works, if so I'll keep the change for the next update
 
I did not have the QuantityPanelPicker set to Open on Start, so that's not it. I did a little bit more digging/testing and I found out the QuantityPickerPanel is showing up immediately when I load the crafting window *only* when I open it with the gamepad button. It appears to be not only opening the crafting panel, but also "clicking" the first item in the list. When I open with just the keyboard, that doesn't happen. I don't have any custom player actions set up for the crafting menu except for an Action button that interacts with Interactables, and I'm not using the UIS-provided CharacterInput mapping at all. I did some debugs, and the button is only being "pressed" once. Any idea what may be causing a gamepad button press to be registering twice?
 
Some users have reported double input when time scale is set to 0. We haven't been able to reproduce it consistently though.
Are you using the normal Input Manager or the new Unity Input System?
 
I'm using the new Unity Input System. I tried unchecking Set Time Scale to Zero When Menu is Opened in the Display Panel Manager, but that didn't seem to affect it.
 
I did a little more digging and added Debug.Log("clicked"); to the top of the CraftingRecipeClicked() method in CraftingMenu.cs. When I open the menu with the gamepad, it does in fact "click" the first item in the recipe list.

Some thoughts...
  1. Could this have anything to do with the InventoryInteractor component on my player that has the Input button (which I've called Action) being the same as the button that is used to open the crafting menu?
  2. Is Submit in the Input System UI Input Module on the EventSystem somehow screwing with this? I know Submit is tied to the recipe list, but I don't think it's being called when you open the crafting menu.
  3. I noticed that if you click a recipe (just with the mouse) and the quantity panel picker show up, then close the window without crafting. If I then reopen the crafting menu, the quantity panel picker is still visible.
 
your first point might be right. I would need to test it to be sure.
Perhaps I could delay opening the Menu by one frame, if that's the case.

Try to replace the Crafting Menu Opener with this and let me know if it works for you:
Code:
/// <summary>
/// Crafting Menu Opener.
/// </summary>
public class CraftingMenuOpener : InventoryPanelOpener<CraftingMenu>
{
    [Tooltip("The Crafter to bind to the menu.")]
    [SerializeField] protected Crafter m_Crafter;
    /// <summary>
    /// Open the menu on for an inventory.
    /// </summary>
    /// <param name="inventory">The inventory.</param>
    public override void Open(Inventory inventory)
    {
        StartCoroutine(DelayedOpen(inventory, 0.1f));
        /*m_Menu.BindInventory(inventory);
        m_Menu.SetCrafter(m_Crafter);
        m_Menu.DisplayPanel.SmartOpen();*/
    }
    public IEnumerator DelayedOpen(Inventory inventory, float delay)
    {
        yield return new WaitForSeconds(delay);
        
        m_Menu.BindInventory(inventory);
        m_Menu.SetCrafter(m_Crafter);
        m_Menu.DisplayPanel.SmartOpen();
    }
}

3) That sounds like a bug. I added this to the CraftingMenu:
Code:
/// <summary>
/// Close the QuantityPickerPanel when the menu is closed.
/// </summary>
public override void OnClose()
{
    base.OnClose();
    if (m_QuantityPickerPanel.IsOpen) {
        m_QuantityPickerPanel.Close(false);
    }
}
 
Both of these fixes worked perfectly! Thanks so much.

One last question - what's the best way to disable/enable the confirm button? I want the player to hold down the craft button for about a second while I play an animation on the button and then have it perform the craft. I have all the code set up, except I need to disable the confirm button until the animation is complete. I tried using EnableConfirm() in ConfirmCancelPanel, but that didn't seem to do anything.
 
I'm glad that worked.
I'm not sure I will keep the first change though. I wish I could do something more generic that could affect all or a subset of the panels, because you'll probably have similar issues with any panel you open on interaction since you interact input is the same as the submit input.
For now I would recommend you create a custom CraftingMenuOpener such that the change you made doesn't get overwritten in the next update.

For your new issue, most likely EnableConfirm does not work because something else is enabling the button right after.
I enable and disable the confirm button depending on the whether or not the player has the ingredients to craft the item. You could try adding a Debug.Log in the EnableConfirm function to see when it is called.

I would recommend you copy paste the CraftingMenu code and perhaps replace the QuantitiyPickerPanel by some custom quantity picker such that you can comfortably customize the craft button to your liking instead of working around it.
 
Top