Forum rules - please read before posting.

Accidental Click-through on Unity UI

I am attempting to create a Unity UI for an inventory, similar to your tutorial. I have a couple buttons that control visibility of elements within the UI. When clicking on these UI elements the character moves when he should not, most likely because the click is also being interpreted as a 'move to location' event.

I would like to stop the character from moving to this location when the UI element is clicked. I have added these elements to the Menu and assigned the clicks to a 'noop' action list. but this does not seem to help (in fact it screws up my animation and adds some fade).

The last odd thing is that this movement is related to aspect ratio. If I have a specific aspect ratio then everything is ok and the clickthrough doesn't happen. If I resize the game window then I can click sometimes and it will move the character. The inventory is in the top left character and the forceAspectRatio code is on.

Any thoughts as to what might be happening? Thanks.

Comments

  • edited October 2016
    A picture of the UI in-game would help and also some screen shots of your uGUI menu settings and the AC menu manager's menu settings too. There are a lot of reasons that could cause this. For example, the bounding box of your UI might not always be covering the same place of the screen if you haven't set the uGUI canvas to resize itself when changing screen sizes. 

    You also need to make sure your uGUI menu is properly connected to AC (in the menu manager) and need to make sure the Canvas group in your UI's canvas is set to interactable and to block raycast. As far as I know, without this the UI will be ignored by raycasting. You will also need to check this option for some of the individual UI elements too (like buttons), and in some (like panels) you may need to add a canvas group to get that functionality. 

    You should also check the tag/layer assigned to your UI elements. There's an Ignore raycast one that sometime's is assigned by default, and that may cause UI elements to be ignored by raycasting too.

    Still, it will be hard to know what the real cause is without more information...
  • AC will prevent "click-throughs" on Unity UI-linked Menus that have a RectTransform boundary assigned in the Menu Manager.  Whether or not a click occurs inside this boundary is how AC determines whether or not it can control Hotspots and Movement vs the UI itself.

    Make a RectTransform child object in your UI prefab that spans the clickable area of your UI and assign it in your Menu's properties as the RectTransform boundary.  Be sure to click Apply on the UI to update any changes to the prefab, and then test it out.

    As @Alverik says, without screenshots to show your issue it's only possible to give general advice at this point - so if you need more help, please post with shots of your UI prefab and entry in the Menu Manager.
  • Thanks for your help, both of you. I believe your intuition is right that it might be related to the RectTransform boundary. I will check it out later today.

    Also I sometimes use EventSystem.current.IsPointerOverGameObject() to determine if UI interaction is occurring, and probably assumed that AC used this as well. Perhaps it would be useful to allow this as an option to determine UI click areas instead of the RectTransform method?

    Thanks again,
    C
  • ummm, I also use IsPointerOverGameObject(), but as far as I know the RectTransform boundary isn't just used for that, it's needed so AC can accurately position the menu on screen (changes in resolution and other things make this important), and also to move the UI when necessary. So, at the end of the day you'll still need to use it... Still, for it to become second nature It helps if you think of your UI hierarchies like this:

    -Canvas
        -Content //This is your boundary, can be an empty or a panel or whatever
            -UI elements go here...

  • Ok, the click-through issue was definitely not having the correct Panel as the menu 'bounds'. I have updated my UI and everything works great! Thanks for your help!

    Alverik: afaik AdventureCreator is not using the RectTransform to position my UI. In fact I had to fix a bug where the UI was not being moved because of the forceAspectRatio setting. Also my UI does generally conform to the hierarchy you mention.
  • edited October 2016
    The positioning is done when you change the position type in the AC menu manager. It's for types like on hotspot, above speaking character, above player, etc. If the bounds are not set, then those don't work right (like it happened in this forum topic)... If you are using a manual position type then it only uses the original position of the UI. In which case all falls to how you've setup your uGUI menu... and actually, aspect ratio also falls on how you've setup your uGUI menu... when you use uGUI, AC only really controls a bit of the stuff the menu does. Like what the buttons do when clicked or the text in the text boxes, or some cases the position of the menu. But, the rest of the appearance is mostly left to whatever you make of it. That's the power and pain you get by using uGUI xD
  • Hi. I'm having the same problem with a customized Subtitles UI. I've added a button to the existing Subtitles prefab, but when you press it, hotspots behind also get triggered.

    I've set the RectTransform boundary, but that doesn't seem to help.

    I've also verified that this is somehow specific to speech, because if I duplicate this menu and make it appear manually, it does in fact prevent click-though.

    Any ideas?
  • In what version of AC?

    Have you enabled speech-skipping?  It may be related to that - try disabling that if so and see if the issue persists.  Also check the state of your Menu's Ignore cursor clicks? option, and your UI's Interactable option.
  • This is AC 1.55c.

    Subtitles are not skippable. They are invoked by a 'Play speech' action, told to Play in background, and the actionlist itself is set to Run in Background. In Speech manager, I have:

      Display subtitles forever until user skips it?: ON
      Subtitles during gameplay can also be skipped: OFF

    The subtitles are meant to stay on during gameplay until players click on something (which kills all speech using an 'Stop speech' action). During that time, I'd like players to be able to tap a button within the Subtitles UI but I'm getting the undesired effect where hotspots behind the UI get triggered too.

    The UI's Interactable option is ON, and the menu's Ignore Cursor clicks option is OFF.

  • That would be the resulting behaviour - you're running the ActionList in the background, which means unless any other ActionList is running, gameplay isn't blocked and Hotspots are still clickable.

    You can use the Engine: Manage systems Action to disable the Interaction system if you need to disable Hotspot-clicking during regular gameplay.  Another such Action could be used after the Dialogue: Stop speech Action to re-enable it.
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.