Forum rules - please read before posting.

Keyboard/controller main menu.

Totally stuck again... ;)

I've followed the AC tutorial on creating main menu and then the 2nd one on how to make it not pause the game. So now I've got my first scene, the main menu shows up as it should (start new game, load, options, no save etc) without pausing anything, but none of the buttons are selected and moving the controller stick does nothing at all (though on few ocassions by wagging it like crazy I managed to hover onto some of the options; still, it felt like something was really off with the input since it wasn't just the vertical axis but both of them it seemed).

After hours of searching through this forum I am now pretty sure I need to use Unity UI to make the controller/keyboard work... But I've tried it and found it pretty hard to understand. I mean, I've put NewGameButton as the First Selected element in my Title menu tab and clearly that's not doing anything. I have no idea what to put in LinkedCanvas or ReactTransform boundary boxes... It feels like I should have Title menu's prefab somewhere but how to I make a prefab of a menu?

Also, I'm pretty sure something's wrong with the Unity inputs. I've got horizontal set to X axis and vertical to Y axis and in game it works alright - I can control my character to walk left and right (direct control 2D game where you can only walk left/right using player constrain movement up/down), I can select inventory items with the stick's X axis but the Y axis is just wild and out of control... (without the up/down constrain the player just flies off to the sky like if the stick is permanently pushed up ;) )

What I'm asking here, I could really benefit from a more in depth tutorial on how to make this menu work with keyboard/controller setup (because it works fine with mouse cursor btw). I know AC is mainly focused on point&click games but adventure games genre seems to go in direct control direction these days more often than not so I think a lot of people would benefit from it.

So yeah, I've spent like 8 hours trying to figure it out already. I need help... ;) Please? ;)
«1

Comments

  • edited May 2016
    This got me confused the first time too, but first, here's the basic tutorial on how to plug a unity UI into an AC menu (make sure to read it, and/or follow it through): 


    Now, if you've done that, I'll also give you a heads up and tell you that the LinkedCanvas and RecTransform must be taken from the prefab in your project folder, not from the one active in your hierarchy windows (I somehow missed it the first time). I should mention too, that any other buttons or labels past the second level in the Unity UI in the hierarchy of the prefab, must be taken from the elements in the hierarchy panel (because they won't show up in the project window), in other words, you'll ned to drop your UI prefab into the scene, open it a drag the elements into the slots of the AC menu elements. Also the First selected field in the AC Menu manager must be the name of the AC UI element counter part (which will work as a container or reference for your Unity UI element). If that doesn't work, for some reason, you may have to resort to using a simple bit of scripting and call a function with the following line (with your button's name,obviously):

    EventSystem.current.SetSelectedGameObject(MyButton);

    Personally, I use several assets which either deal with input or the event system and so, AC's First Selected's never really worked for me either. But calling this bit of coding when the menu is opened always does the trick.
  • RemRem
    edited May 2016
    My initial response was... but I'm not trying to build another inventory!

    Then... I thought "screw it, maybe I'll learn something in the process". So I followed the tutorial and made the inventory, realized that it's not that hard after all ;) I went and built a main menu based on this new knowledge and voila! I've got a basic yet lovely menu, I can highlight buttons with keyboard/controller and press on them to make them click. Perfect! I've got two problems though: the clicking doesn't do anything and menu:turn on/off doesn't work on it, except if I leave it in the scene - then it's visible from the start. So I guess I'm still missing something... but progress!!!

    (and just before you ask, I did add for the start new game button the Click Type: Run Action List with the little action assigned inside to turn off the menu and start moving the camera... except it doesn't do anything for some reason).

    Any idea why this could be happening?
  • It sounds like your Menu's elements (as defined by the Menu Manager) are not properly linked to their relevant Unity UI buttons.  Drag the UI prefab into the scene, then drag the UI Buttons onto the Menu Element "Linked Button" fields.  Then apply changes to the prefab and remove from the scene.

    Know that each of the Menus in the default Menu Manager (Demo_MenuManager) have Unity UI counterparts, which you can pick apart for learning with.  Just change the "Source" for e.g. the default Pause menu to Unity Ui Prefab, and you should see it's associated UI listed beneath.
  • edited May 2016
    The buttons may not be connected right or at all... try to think of the process as if you were pluging cables, a unity button would be the cable and the AC Button would be the socket. so if you create 5 buttons in your Unity menu, you have to create 5 AC buttons(sockets) where you will later connect the afore mentioned (mind you, in this case the AC buttons can be practically blank, you don't need to worry about positioning or anything, except for the default text you want displayed in a button).

    Right, I forgot this is covered in the video tutorials, you can find an explanation in the 2.5D tutorial. At 2h:07m:34s:


     

    Also remember that the RecTransform refers to, well, the RectTransform of a UI component (same as the transform component for regular objects, but just for UI). As Chris said in the video, the RectTranform is the boundary (imaginary boundary) where the UI elements are placed inside the canvas. If you don't know these stuff yet, you may want to take a quick look at the Unity UI tutorials (11 videos), which are actually quite short and to the point:


    Now, you're probably wondering: and what's the point of Using Unity UI?? well, AC UI is super easy to use, but has limited transition effects, and a few not always used elements are missing (scroll bar and scroll rect for example). Now you are probably wondering: and what's the point of connecting the Unity UI I made into AC?? Well, simply put, you will get all the functionality you get from an AC UI element with no coding, and I mean things like: running action lists from any of your new fangled, better looking and better animated buttons, or using text labels to show an item property or the content of a variable (like for scores, player name, whatever you can think of), also you can use your custom shaped Inventory grids to display item names or icons, and all of these by taking advantage of the node logic from AC (or simple choices you can do in the menu manager by just ticking a check box or clicking a drop drown list). So, it does have many uses. The only times where you may need to do some scripting is for doing things that aren't natively built-In in Unity, like Tabbed menus, you'll have to do a bit of scripting with those, want it or not...

    Anyways, my advice is that you take a few tutorials on Unity UI and also to go ahead and check out the video segment of the 2.5D AC video that shows the use of unity UI in AC, so that you can get your bearings, because as Chris said, you probably still haven't plugged everything right.

    EDIT: Also, while you test a menu, tick the Enabled on start? so that you can actually see if it opens or not. You should not have to place the prefab in the scene hierarchy, it'll usually not do anything that way, so it may just be that you have your menu set to start "manually", and if that's the case it's never going to show up unless you actually call the menu from an action (Menu - Turn On)...
  • Chris, Alverik - your help is really appreciated :) I did plug the buttons in AC but after testing the boxes kept going blank again, even though I remembered to hit that apply button in the inspector... But I will have another go when I get home. I will report back on that later ;)
  • edited May 2016
    Cool, but just in case I'll repeat what I said in my EDIT in my previous post (it may have been too late for you to notice it):

    Also, while you test a menu, tick the Enabled on start? so that you can actually see if it opens or not. You should not have to place the prefab in the scene hierarchy, it'll usually not do anything that way, so it may just be that you have your menu set to start "manually", and if that's the case it's never going to show up unless you actually call the menu from an action (Menu - Turn On)...

    Also:

    try to think of the process as if you were pluging cables, a unity button would be the cable and the AC Button would be the socket. so if you create 5 buttons in your Unity menu, you have to create 5 AC buttons(sockets) where you will later connect the afore mentioned (mind you, in this case the AC buttons can be practically blank, you don't need to worry about positioning or anything, except for the default text you want displayed in a button).

    In short, the text you type in the Unity UI button is redundant, because AC overwrites that text, with the text in its own button text field in the menu manager (if you don't put anything in that field, the button will have no text at all).
  • RemRem
    edited May 2016
    Hmm...

    The menu does appear for a split second like seen on the first image and then all buttons go completely blank and don't respond anymore.

    http://i.imgur.com/0mf2Z6c.png

    It seems all is plugged in alright, the fields are still blank but the ID numbers show...

    http://i.imgur.com/6qIxgoZ.png

    I added the Event System to the prefab which I believe takes care of keyboard controls for the menu (and in fact does work when my menu is left in the scene, though presses don't produce any effects...)

    PS. It doesn't show up when set to enabled on start...
  • Ok, my progress so far... ;)

    -The menu pops up okay, the buttons are no longer blank because now I've put text in AC instead. (Thanks for the tip ;) )

    -I can click on it with mouse cursor and it does start the game, but keyboard/controller still does nothing (despite the fact that when it is left in scene the keyboard works and the buttons get highlighted, except then they don't start the game; I know you said menu won't work that way so I'm not surprised, just a little curious why keyboard only works there...?) Once I remove it from the scene the menu becomes unresponsive to keyboard again.

    - This line of code: EventSystem.current.SetSelectedGameObject(MyButton);  - I don't really know what to do with it. Where do I add it?... Is this the reason keyboard controls don't kick in? Which part of the menu (canvas, panel or grid) should I add the standalone input module to, if any at all?

    Sorry to bother you so much with these but I feel like I've followed every single step correctly and I'm really close to getting the result I want.


  • Hi, good to know you are progressing. Anyways, I watched your screenshots and I noticed something strange in your UI canvas: you seem to have added an Event System's components directly to it?  ^#(^ I noticed you disabled one of the components from the Event system (the Event system Script), but you didn't disable the "Standalone Input module" which is also part of the Event system. I think you may get conflicts if you have those repeated, so if you already have an event system in the scene or the prefab it would be best to remove the unnecessary components you added to your canvas object. 

    Also, unless the menu is gonna be enabled all the time, or it's gonna be the only menu, I don't recommend you putting the event system in your UI prefab, because all UI menus need an event system, and Unity doesn't allow multiple Event systems, so if you were by any chance to open a second menu at the same time - like a HUD showing a score, etc - and that one had its own Event System in the prefab too, then they would conflict, also if your main menu had the Event system and it was disabled, so would the Event system be disabled with it... 

    An easy fix would be to ask AC to create it for you on every scene, just go to the top of the Menu manager, there you have a slot to drop an event system prefab (so just create an event system, configure it to your liking, then drop it in the project window to create a prefab, and then put that in the "Default even system" in the AC menu manager. Just remember, every time you create a Canvas, Unity automatically creates an Event system with it for safety, so remember to delete those every time you create a new UI canvas (cause AC will be creating the event system on start on every scene anyway, so you don't need the extra Event systems).

    Now, seeing how you've barely customized your buttons yet, it may be that they're actually working... you just can't tell, because you may have not set a highlighted color or animation, to put it simply, when a button is "selected" or "hovered" they will run the corresponding states as it appear in the button's inspector (options are color change, change graphic or run an animation), and by default the "highlight" state is set to almost the same white (if not the same...) as the normal state, so it may look like nothing's happened when you highlight the button (imply because both states have the same color...).

    Now, for the code, I've made a small script you can use right away. Just attach it to your canvas, then, as you will notice, a field will appear under the new "Set UI Focus" component called "My Button". All you have to do is drag and drop your button from the scene hierarchy and into the slot. Also, although I've named the field "My Button" it actually takes any GameObject, so you can actually use the same script if you want to highlight any UI element which is not a button, like a scrollbar, a toggle, etc. Here is the script (just remember to first check if the highlighting isn't already working):


    Anyway, make sure to keep studying UI video tutorials, because unity UI is more flexible, but also harder to get...
  • RemRem
    edited May 2016
    I got it! :) :) :)

    Thank  you so much, Alverik! :)

    I removed all the extra Event systems, added your SetUIFocus to my canvas and changed menu's appearance to During Gameplay and now it's working!

    I do watch plenty of online tutorials on all different aspects of using Unity but some things are hard to find... or sometimes just worded in a way that doesn't quite explain what you need to know. Anyway, once more, I really appreciate yours and Chris's help ;) Couldn't have done it without you ;)

    I'm sure I'll be back soon for more help hehe ;) But the game's progressing day by day. Here's the first scene: 

    image
  • edited May 2016
    Nice!, the scene already looks great! Man, I've always sucked at 2D, lol. By the way, you said in a post you were the developer of the Cat Lady? or did I get that wrong?
  • Yeah, I am ;) Trying to make a swtich from AGS to Unity. I just love all the new toys ;) (if only I knew how to use them properly haha ;) )



  • Cool. Personally I've only had the chance to have a few glimpses at the beginning of Cat Lady (looked real good), but my sister really, really loved it (she's a great fan of scary/horror stuff).

    by the way, regarding the new "toys", Lol. Yeah, Unity has a lot to offer. When I started to want to make games I checked AGS for a while. Personally I'd seen Unity before, but it had been like 2 years prior to that point and it had felt like... not good enough. Luckily though, the prospect of working mostly in 2D (which I suck at) made me try checking again :)), and man I was lucky, Unity 5 had just come out and it was shinny and cool and so much better than what I had seen before, and it got me hooked. Though, I must admit it took me two or three video courses to get my bearings right. Free or paid, you'll want to check a tutorial on 1. the actual unity in general, 2. mecanim, 3 Unity GUI, 4. Lights/ light baking, 5 Navmesh. The rest I've filled up by way of some asset store plugins (like AC) and a sh*t load of google searches every time I want to know how to do something ;)

    Anyway, although for now I'm just an uninitiated hobbyist (just started my first real project like 2 months ago :)), I've still piled up a bit of Unity knowledge (started learning unity more than 6 months ago :-B), so anytime you feel lost, I'll try giving you a hand \m/.
  • Excellent :) Might PM you sometimes when I get stuck again ;)
  • Posting this on this public thread as it wasn't posting without approval, so I sent Chris a private message and we discussed but thought it might be helpful for others (it's still ongoing):

    ---

    ME: So I keep bouncing from this thread to the ReWired one for putting the final touches on my game controller implementation.  I'm super close but one hurdle that I'm running into is how to deal with custom save game labels (https://adventurecreator.org/tutorials/custom-save-game-labels). 

    If using mouse, I can click in the input box and I can then type whatever I want but if I'm using a controller, I can never get the text input cursor to appear.  If I click the button I have associated with submit on the input box like I would with the moust, it plays the sound that I have set up for a submit, but doesn't let me change the name at all, so I can't type anything into the input box.  I need to switch over to mouse & keyboard in order to select the box and to type in a custom name.  I've tried setting up an actionlist to manage systems to maybe give me a mouse cursor using my controller (right stick controls the cursor) but no dice.  I'm guessing it's because it's an in-game menu, so it's pausing the game.

    ---

    CHRIS: Is your menu displayed using AC or Unity UI?  What's the first element that's to be auto-selected when the menu turns on?  If it's the Input box, try the "Submit" button and then navigating to the Input box from there.

    A Menu will only pause the game if "Pause game when enabled?" is checked.  You can determine the game's state at any time via tha "AC Status" box option at the bottom of the Settings Manager.

    ---

    ME: The menu is an AC one...and I'm not seeing an option to auto-select a particular element.  Here's a screengrab: 

    https://imgur.com/a/8nCIG0g

    I think the only time I've seen the auto select option show up is if I make it a Unity UI menu.

    And it's definitely paused.  It's the in-game save menu, so I made sure the "Pause game when enabled" option was flagged.

    ---

    CHRIS:  If it's AC, then the first in the stack will be auto-selected.   Swap around the Button and Input to see if you can navigate to it that way.

    You're not using the latest version, so please update - even if it's in a test/duplicate project - so that we can discount any already-solved issues.  In the latest version of AC, I can't see an issue with InputBox fields not being selectable.  Actually, they don't even need to be selected before accepting input - so I'll be making this optional in the next release.
  • @ChrisIceBox - Just so you know, I tried flipping the button and input around and updated to the latest version of AC and it's still not working (also have come across a few bugs since updating but I haven't had much time to dive into that yet...I'll reach out if I need to).
  • If you create a .unitypackage file of all your Managers, and menu-related assets (e.g. graphics, ActionLists), PM it to me with clear steps on how to access the menu to see the problem, I'll take a look.
  • edited October 2018
    Heya @ChrisIceBox.  Actually totally missed this response as I had to go out of the country for a week and then promptly got buried when I returned.  I'll try to get this stuff packaged up but in the mean time, I'm in the process of finishing adding game controller support in my game and had a question. Is there a global method of having an input button cancel out of the current menu and go back to the previous one? Issue is that if you press the B button (on an xbox controller, for example), you expect that to go back a page but it's actually just selecting the option that's highlighted. Poked around on the forums and couldn't find anything.
  • You can use Active Inputs for that - see the Manual chapter of the same name.

    An Active Input mapped to the "B" button can check if a given Menu is on (Menu: Check state Action), and close it/open another one if so (Menu: Change state).

    Alternatively, if your Menu features a "Back" button on it, you can define an Alternative input button in the Button's properties to trigger it when that input is pressed - as opposed to the Button element itself.
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.