Forum rules - please read before posting.

Unity UI buttons not linked to AC not working

I have most of my game dialogues, which are created as Unity UI, managed using AC's menu system and all works fine.

There is however one dialogue which I wanted to create without it being managed by AC and I have an issue: the Unity UI buttons on the dialogue don't seem to be responding to mouse clicks. However, if I click on ESC to obtain the AC Pause menu, then click on one of the "special" dialogues buttons and then click on Resume on the AC Pause menu to close it, the button is effectively triggered (and calls my code attached to its canvas). I therefore suspect it's something to do with AC managing the game interactions.

I have already checked the following:

- There is an EventSystem in my hierarchy (tried having Force Module Active checked and unchecked, no change)
- My code does have "using Unity.EventSystems" (makes sense since it is capturing the buttons when they are detected)
- The canvas on which the buttons are placed does have a Graphic Raycaster component
- The buttons do have a Button script which manages the OnClick to call my code and has Interactable checked
- The image on the buttons does have Raycast target ticked and there are no other objects in front of the canvas

Any ideas?

Comments

  • I'd first try it in an empty/non-AC scene to be sure that AC isn't affecting it.

    When the game is paused, AC places the game's Time.timeScale to zero, and one when resumed - I can't imagine how else it may influence any unconnected UI.

    Does the UI Button transition correctly (e.g. colour changes with hover/click events)?

    Try also placing a Debug.Log statement in the function that's supposed to be run, so you can confirm if it's being called at all.
  • edited May 2018
    Did create a new empty scene, pasted the canvas with the dialogue, added the EventSystem gameobject to the hierarchy and now all works fine.

    When using in the scene with AC, the button doesn't transition, except in the situation mentioned above (after leaving AC Pause menu) and it does call my code in that case.

    Other interesting point: When I added AC back to this new scene (by clicking on With Folders in the scene manager), my canvas disappeared (it started flying off). I had to change its canvas render mode from World Space to Screen Space Overlay. The dialogue was then visible and it does work.

    This seems to indicate something else is preventing the dialogue from working in my game's scene, but I can't see what it could be. Any insights?
  • Does it require a special EventSystem?  You can assign one to the Menu Manager, if required.
  • No, just added the standard EventSystem to the new blank scene.

    I have noticed in the past a message about Unity's EventSystem possibly interfering with AC's event management. I noticed that you can provide a link to an event system prefab from AC's Menu tab, but not sure if that would be related to my issue? 
  • edited May 2018
    I have found what is causing the issue. It's related to cursor locking.

    If I uncheck "Lock cursor in screen centre when game begins" in AC's settings, when the dialogue is displayed and I click on the buttons, they work (also works if I select the key in Unity's inputs to "toggle cursor").

    So as a solution to my issue, I can just unlock the cursor when I display the dialogue. Not sure however if this is normal behaviour or if something needs changing in AC so that the cursor can still click on Unity UI buttons when "locked" by AC (as it is possible to click on other objects which have hotspots).
  • So to solve the problem, in the code when I display my dialogue, I added:

    KickStarter.playerInput.SetInGameCursorState (false);

    Which now allows me to use the dialogue's buttons properly. As the dialogue is within the "game's world", I also wanted to force the player (in first person mode) to be facing the dialogue and to move close to it.

    To do this, in the Playmaker FSM controlling the display of the dialogue, I used the 
    "Smooth Look At" and "Move Towards" actions and it works fine.

    One new issue. In the function closing my dialogue in the code, I call:

    KickStarter.playerInput.SetInGameCursorState (true);

    To revert navigation back to AC. The issue is that I can move the player's "head" up and down and still move around with the arrow keys, but can't use mouse right and mouse left anymore. The cursor is locked in the centre of the screen, but only up and down movement is possible.

    I unchecked the Playmaker actions in the FSM one by one and noticed that the issue is due to the "Smooth Look At" action. If this is disabled, all works fine and after the dialogue closes, the AC navigation works fine again.

    I also tried this in my dialogue's closing function, but the issue remains:

    KickStarter.playerInput.InitialiseCursorLock(MovementMethod.FirstPerson);

    Any idea what the smooth look at action in PM changes that prevents AC reverting to normal working state?
  • I don't know how it works, but it sounds like it's still active, somehow.

    It could be related to the fact that FPS camera movement works by spinning the player, and pitching the camera - so the FPS camera itself is only supposed to move up/down.

    If you're using script, you may have to force the player to face the camera's forward direction (no Y-value), while also clearing the camera's spin.

    Alternatively, you could use the Object: Face object Action, which allows you to turn the AC FPS camera to face a given target.
  • I finally combined the AC Character: Face Object action as you recommended with the Playmaker Move Towards action and also disabled the HUD which was controlled by AC by using  KickStarter.stateHandler.SetMenuSystem (false) in my code and all works fine now.

    Just need to be careful that the AC Character actions don't respond once the cursor is unlocked using  KickStarter.playerInput.SetInGameCursorState (false) to be able to access the Unity buttons on my dialogue.

    Thanks for your insights.
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.