Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

Auto Highlight first menu option issue...

Hiya everyone!
I have my conversation menu set up to auto highlight the first option upon opening the menu. This works great, but I only want this behavior when the player is using the Controller and Keyboard input option. (I allow the user to switch between controller and keyboard at will). Can I get some help making sure the auto highlight option only works if the player is using a Controller, but not when using the mouse? Im not a programmer so wtiting the code for this myself is not something I can do.

Comments

  • Here's a custom Action to check the game's current input method:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionCheckInputMethod : ActionCheck
        {
    
            public InputMethod inputMethod;
    
            public ActionCheckInputMethod ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Input;
                title = "Check method";
            }
    
            public override bool CheckCondition ()
            {
                return (KickStarter.settingsManager.inputMethod == inputMethod);
            }
    
            #if UNITY_EDITOR
    
            public override void ShowGUI ()
            {
                inputMethod = (InputMethod) EditorGUILayout.EnumPopup ("Check input is: " + inputMethod);
            }
    
            #endif
    
        }
    
    }
    
  • This action works great for detecting the current method, but I could also just use my assigned global variable for that. What I cant seem to do is toggle the Auto Select First Visible Element.

    I have this set globally in the menu properties. Ive tried un-checking this option and instead using an action list when the menu turns on to set the auto select nature, but when I try to use an actionlist, it ignores any auto select first visible element command whether it's in the action list or the menu properties itself.

    Using Source: Unity UI Prefab

    Currently using Unity 2018.2.17f1
    AC: v1.67.4

  • Changes to a Menu's properties in the Menu Manager at runtime won't be reflected until the game is restarted, but you can access the "live" instances of them through script.

    Right-click the Auto-select first visible Element? field to get an API reference to it. Something in the form of:

    AC.PlayerMenus.GetMenuWithName ("Conversation").autoSelectFirstVisibleElement
    

    You can set this to true/false to change it at runtime, but doing so in an "ActionList when turn on" is likely too late. Set it instead at the same time that you change the input method / global variable.

  • Im very sorry for my ignorance, but I don't know what to do with this bit of code.
    Right clicking on the field game me this result (As you stated):

    AC.PlayerMenus.GetMenuWithName ("Conversation").autoSelectFirstVisibleElement

    But I don't know what to do with this.
    When the player starts the game, they choose an input method via custom action script. I Also set the global varaibe (IsUsingJoystick) via actionscript at that time.

  • You'll want to use it whenever you change the input method:

    bool directControlMenu = (KickStarter.settingsManager.inputMethod == InputMethod.MouseAndKeyboard);
    PlayerMenus.GetMenuWithName ("Conversation").autoSelectFirstVisibleElement = directControlMenu;
    

    You should also run it when the game begins even if this choice is not given, so that it's always set to the correct value - as it'll be reset when the game is launched.

  • Again I apologize for my ignorance, but I am not a coder. How exactly do I "run" this line of code?
  • Hi,

    you could turn this code into a custom action based on the tutorial.

    But the simplest implementation would probably be creating a custom script and then use the Object: Call event action.

    You would create and empty object in your scene, put the script on it and then drag and drop the object in the Call event action and select the "UpdateMenu" method. You can pass the name of the menu as a parameter.

    using UnityEngine;
    
    public class MenuElementSelect : MonoBehaviour {
    
        public void UpdateMenu(string menu) {
            AC.PlayerMenus.GetMenuWithName(menu).autoSelectFirstVisibleElement = (AC.KickStarter.settingsManager.inputMethod == AC.InputMethod.MouseAndKeyboard);
        }
    
    }
    
  • Yes, indeed. Going further, you can also make this new GameObject a prefab, and then just reference the prefab itself with the Object: Call event Action. There's no need in this instance for it to be actually present in the scene itself.

  • Thank you both so much for the help! This is working great now!

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.
Do NOT follow this link or you will be banned from the site!