Forum rules - please read before posting.

Direct control of options in Unity UI menus

Quick question... when using AC menus (for conversations) the first element is selected automatically and I can cycle through the options with a controller. But I can't seem to duplicate this behavior when using a Unity UI menu (prefab). The "First selected element" doesn't seem to be working here (also tried switching over to the demo example).

Apologies if I'm missing something obvious!


Comments

  • AC doesn't override anything when it comes to navigating Unity UI elements, so if it's not working then it's likely down to the way your UI is set up, or your Event System.
  • I'm not sure where to look into this further to be honest. I have a ConversationUI prefab. When I just put that prefab in my scene and start the game I am able to see the first item selected and can navigate with the keyboard or game controller. IE - everything works as expected (this is a very simple setup: panel and buttons with an EventSystem)

    However, when the prefab is instantiated by AC the first item is NOT selected and I can't navigate the panel of buttons. I've tried both as a prefab and as a UI in scene.

    Are you able to navigate with cursor keys on your included conversation UI prefabs? I see the exact same behavior as above (after adding the EventSystem of course).

    It seems like the panel does not take focus when enabled in this manner? I can also replicate this behavior by starting the scene with the panel disabled and then manually enabling it.
  • Are you able to navigate with cursor keys on your included conversation
    UI prefabs? I see the exact same behavior as above (after adding the
    EventSystem of course).

    Yes, I am.  The EventSystem is created automatically by AC unless you specifiy an override in the Menu Manager.

    Which versions of AC and Unity are you using?  It may be an issue introduced with an update to Unity.
  • Thanks for your help... Using Unity 5.3.3f1 and AC 1.50i.

    1. Created new project, imported AC
    2. Assigned Demo manages
    3. Loaded demo scene
    4. Changed conversation menu to Unity Ui Prefab
    5. Hit play

    Definitely not able to scroll through the menu options with keyboard/controller. In my project I'm using Direct Control, but neither is working here.

    I've tried entering something into "First selected element" but doesn't seem to do anything. (What exactly is one meant to enter here... an int?)

    Any ideas?
  • edited February 2016
    If this is really working for you I feel like I must be missing something really obvious here... I just tested in 5.3.2 as well as an older version of AC and the behavior is same (also tried PC and Mac).

    Seems like this was brought up before:


  • edited February 2016
    Sorry to spam with responses, but perhaps this might help.

    It seems that public GameObject GetObjectToSelect () (in menus.cs) is always returning null (even when the correct name of an element is present). 

    I'd guess that this evaluation is causing the issue: if (element.title == firstSelectedElement)

    I can hack around this by returning visibleElements[0].GetObjectToSelect();

    ...but that seems potentially dangerous since I'm not very familiar with the actual AC codebase as a whole.

    Hopefully this all makes more sense to you, Chris!
  • The only thing I can infer from that is that the element's title doesn't match the firstSelectedElement string.  I'm assuming you've entered it in properly, so I can't see why there'd be a mismatch.

    The change itself isn't too dangerous - it'd only cause a problem if you had a Menu with no visible elements.  However, the "First selected element" feature is more of an override than anything: even without setting one explicitly, Unity should still highlight one when the UI is enabled.  Does this change allow you to now navigate the UI?
  • I'm assuming you've entered it in properly, so I can't see why there'd be a mismatch.

    Yes, I've definitely entered it correctly...
    The change itself isn't too dangerous - it'd only cause a problem if you had a Menu with no visible elements.  However, the "First selected element" feature is more of an override than anything: even without setting one explicitly, Unity should still highlight one when the UI is enabled.

    Unfortunately, that's not my understanding now that I've poked through the Unity UI stuff a bit more. If you don't explicitly set a first-selected item the buttons will not be navigate-able via keyboard/controllers until one is first selected with a mouse (and Unity does NOT select one automatically). That can be done either with the Unity UI itself on the EventSystem GUI or with script I believe: 

    public class SelectOnAwake : MonoBehaviour {
    public GameObject buttonToSelectOnAwake;
    public RectTransform panel;
    void Awake () {
    EventSystem.current.SetSelectedGameObject(buttonToSelectOnAwake);
    }
    }

    The problem is that the way AC is currently working it appears to override the selected item regardless - so even if I tell AC to use my own EventSystem prefab that has the first-selected item filled in it gets overwritten even when no value exists in the "First selected element" value in the menu manager.

    The bottom line is that this would all work if that "First selected element" value was doing what it is supposed to.

    Does this change allow you to now navigate the UI?

    That code change did bring back the navigation  - EXCEPT when a conversation was started after a camera switch.

    The thing that is nagging is that you say it's working for you! I can't imagine what's going on here if that's the case. 
  • (the code change works after a camera cut if the action list is set to run in the background, but otherwise the camera change deselects the UI element somehow)
  • The problem is that the way AC is currently working it appears to
    override the selected item regardless - so even if I tell AC to use my own EventSystem prefab that has the first-selected item filled in it gets overwritten even when no value exists in the "First selected element" value in the menu manager.

    If you open up PlayerMenus.cs and find the FindFirstSelectedElement() function, you can see that the EventSystem is still called even if no appropriate element is found.  A null check there may prevent that.

    The thing that is nagging is that you say it's working for you! I can't imagine what's going on here if that's the case.

    An all-too-common issue when using Unity, I'm afraid.  But you can see from the if (element.title == firstSelectedElement) check that a regular string comparison appears to be failing.  Try inserting the following line above that, so that we can get some debug info in the console:

    Debug.Log ("Element: '" + element.title + "', FirstSelectedElement: '" + firstSelectedElement + "', Compares? " + (element.title == firstSelectedElement).ToString ());
  • edited March 2016
    Here is the result from the log using the included convo prefab in the demo scene (talking to Brain):

    image

    Perhaps element.title is not returning what it should?
  • Ok... I see the light... and I believe this is completely my misunderstanding. Please forgive the bother!

    I assumed the "element" referred to the first button in the UI prefab - but it in fact refers to the menu element in the AC editor. Ugh...my mistake.

    I think my confusion stemmed from the fact that the "first selected" is used in Unity's UI system for that exact purpose and I assumed you were using the same nomenclature. But the "element" word was critical.

    Again, sorry for the bother... I really do try to exhaust my self-diagnosis-skills before bothering you Chris.
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.