Forum rules - please read before posting.

Custom Conversation Option Selection

Hello again!

After changing our project to the new input system (thanks for the help on that), I'm having an issue determining how to granularly / manually handle conversation option changes and the devices controlling them.

Conversations are currently 99% of our game. I'm switching between allowing and not allowing "Directly navigate during Conversations?" ... since that seems to allow me to use keyboard (up/down/w/s) for conversation traversal when the player creates input on the keyboard. And when the mouse is in use, I want that to be the preferred input method. But if the player pressed a keyboard key again, it should switch back to keyboard mode and disable the mouse until it's moved again.

First question: Is there an easier way to enable/disable direct keyboard control and mouse controls in such a situation and I'm just missing it?

Second question: The problem I'm experiencing right now is that when I switch back and forth from allowing the direct navigation in code, the conversation selection seemingly stops working. The mouse cursor will go away, but the conversation "icon" that we normally see alongside the selected conversation option is gone, my up/down arrow keys don't select anything, and I can't press my InteractionA input to submit a selection. I guess I'm just not sure how to re-select the first option in the conversation after switching back to the keyboard inputs with "Directly navigate" set to to true.

Third: I'd like to know how to change the currently active / hovered / selected conversation option via code. Is it as simple as changing currentConversation.selectedOption = aDifferentOption, where currentConversation is the Conversation object passed in when I subscribe to the OnStartConversation event? It doesn't seem to be working for me, unfortunately.

As always, any guidance would be much appreciated. Thanks for your time and help!

Very respectfully,
Tyler

Comments

  • Is there an easier way to enable/disable direct keyboard control and mouse controls in such a situation and I'm just missing it?

    To switch between exclusive use of either the mouse, or keyboard, you'll need to toggle the Directly navigate menus during Conversations? option as you are.

    However, if you're using AC's Input System integration, do be aware that its Controls Reader component provides the ability to fire an event when it detects a different Control Scheme being used. This can be hooked into from its Inspector.

    when I switch back and forth from allowing the direct navigation in code, the conversation selection seemingly stops working.

    Menu selection should be automatic if you're using AC as the Source - are you using Unity UI?

    If you need to force the selection of a Menu element, you can either do this with the Menu: Select Action, or through code with the Menu class's Select function.

    var menu = PlayerMenus.GetMenuWithName("Conversation");
    if (menu.IsOn())
    {
        menu.Select("DialogueList", 0);
    }
    

    I'd like to know how to change the currently active / hovered / selected conversation option via code.

    The "0" in the above line represented the index of the visible options. It's a little bit more tricky if you want this to refer to a specific option as defined in the Conversation's Inspector, as the list may be offset or certain options hidden. Is that what you're looking to do?

  • Thanks for the heads-up on the Controls Reader! I'll look into utilizing that.

    We are using a Unity UI Prefab for the Conversation menu's Source. Is that going to cause issues? Or do I just need to make any manual / code adjustments?

    Also, the code you sent seems to be exactly what I need for the purpose of getting the dialog option selected, thank you.

  • We are using a Unity UI Prefab for the Conversation menu's Source. Is that going to cause issues? Or do I just need to make any manual / code adjustments?

    That's the recommended option, as it offers greater stylistic control over the built-in AC option. The only thing to look out for is that - as you've found - Unity UI takes over in terms of selection duties. This should be fine when working with a fixed input method / control scheme, but you may need the custom code to enforce selection when switching.

  • Thanks for the guidance! The current requested implementation is fluid, so it's been a small custom script.

    Last set of questions, I think, and the controls for keyboard and mouse swapping should be working swell.

    Situation: After I toggle back to keyboardControlWhenDialogOptions = true, the mouse cursor disappears as expected and the direct keyboard control begins working, but the dialog option the mouse cursor was hovered over stays selected. So I end up with the keyboard selected option and the former mouse-hovered option showing up as selected in the list at the same time. I don't know if clearing the selections would help here if it's got something to do with the mouse still somehow casting and hitting the UI? If I don't have the mouse hovered over the conversation options, it works fine.

    Second Situation: When I switch from Keyboard back over to Mouse with keyboardControlWhenDialogOptions = false, the last selected keyboard option remains selected, and it doesn't visually clear the "selected" status in the dialog list until I click somewhere outside of the conversation list. Then the previous keyboard option clears. Not really sure what's going on here.

    Is there a way of clearing the directly-selected option in the menu's dialog list when I manually do the switch? I feel like there are some initializing steps involved with having that boolean enable or disabled at the start of the game that I need to reproduce / reset whenever I switch over if it's going to work right.

    Thank you so much again for all the help. We appreciate the assistance in getting our control scheme just right.

    Very respectfully,
    Tyler

  • edited January 31

    After switching over, try calling this to force the de-selection of the current GameObject:

    AC.KickStarter.playerMenus.SelectUIElement(null);
    

    What you're describing sounds very similar to what was Unity's built-in behaviour for UI selection - at least before the use of Input System. To get around this, AC adds the Optional Mouse Input Module to limit selection to either keyboard/controller, or the mouse pointer. Unfortunately Input System relies on a completely different Input module so it's not possible to transfer this.

    Let's try the above function and see if it makes any improvements. You can optionally replace "null" with the GameObject you want to force selection of, but otherwise be sure to call it before any use of the Menu: Select Action.

  • The good news is that it works for when I switch from keyboard to mouse input. Unfortunately, it doesn't work when I go from mouse to keyboard (while I was hovering with the mouse). I'm thinking something in Unity Input may still be raycasting.

    Illustration included, just in case seeing it helps with any advice. Since the cursor is no longer visible in the screenshot, I added a green dot to show where the mouse cursor sits when I transition over to the keyboard / direct-navigation toggle.

    Thank so much again. I'll start digging through documentation, too, in case there's a way to toggle raycasting off on the menus or something when I make this switch. It's the only thing that I can think of right now. Seems messy, though.

    Very respectfully,
    Tyler

  • You could try attaching a Canvas Group to the root, and unchecking "Blocks Raycasts" at the time of the switch.

    Try also manually locking the Cursor. AC will control this automatically under certain conditions, but it may need setting at the time you switch to keyboard:

    Cursor.lockState = CursorLockMode.Locked;
    
  • Unfortunately the lockState solution didn't work for me either.

    I ended up getting a reference to the Canvas Group that was already on my root ConversationUI instance and toggling the "Blocks Raycast" option, as suggested, and that did work :smile: Thank you so much, sir!

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.