Search Unity

Unable to get event to fire when mouse is clicked

Discussion in 'Input System' started by Craziac, Jan 21, 2020.

  1. Craziac

    Craziac

    Joined:
    Dec 12, 2015
    Posts:
    3
    I have been using Unity's new input system reasonably successfully thus far. However right now, I'm having a bit of an issue with something that I would think would be rather simple: registering mouse clicks.

    I am using an almost-default input asset (with Player and UI controls), and for the most part these are working. At the end of a level of my game, though, there is a UI where the player can see a text field count up from zero to the score the player got (e.g. starts at 0, goes to 1, 2, ..., 505). Since not all players would care to see the number count up, however, I'd like them to be able to skip it by pressing A on the controller or clicking anywhere on the screen.

    I have a Player Input component on the result screen that uses the UI mapping of the input asset. Behavior is set to "Invoke Unity Events", and I have both Submit and Click mapped to my event. It triggers if I press A on the controller; it does not trigger if I click.

    I also tried with RightClick, MiddleClick, and so on. I even created my own action called FreeClick, and played around with the "Action Type" and "Control Type" settings. Nothing has worked.

    upload_2020-1-20_17-57-33.png

    upload_2020-1-20_17-57-45.png

    upload_2020-1-20_17-57-55.png

    upload_2020-1-20_17-57-11.png

    I'm hoping I'm just missing something simple, but I'm not sure. I couldn't find any documentation specifically on clicking, without just using Mouse.current, which shouldn't be necessary as I understand it.

    Any thoughts on why Click, RightClick, MiddleClick, and FreeClick will not trigger my event?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    What does the input debugger (Window >> Analysis >> Input Debugger) say? Are the relevant actions enabled at that point and bound to the respective controls? (each player should appear under the "Users" section along with the devices, actions, and bound controls)
     
  3. Craziac

    Craziac

    Joined:
    Dec 12, 2015
    Posts:
    3
    Thanks for the suggestion. I've used the debugger a bit but wasn't exactly sure what to look for.

    It's interesting -- I can see the action bound correctly:
    upload_2020-1-21_16-33-50.png

    However, under the "Users" section, there are two users; one has Player controls enabled and UI disabled, and the other user has it the other way around:
    upload_2020-1-21_16-34-48.png

    Any idea what might be causing this, and how I can enable the actions? My game only has one user (who can use any input device they like), but since there are different Action Maps, I need multiple Player Input components to handle them.

    Thanks!
     
  4. Craziac

    Craziac

    Joined:
    Dec 12, 2015
    Posts:
    3
    Okay, I've resolved this. However, it has some implications that I'm not a fan of, but it is what it is.

    The basic reason for this is that you cannot have two Player Input components going at once unless they are for two separate users, basically. My initial thought (as I wrote in my previous post) was that I need a Player Input for each user and for each asset map (in this case, two: one for User #1 "Player" map, and one for User #1 "UI" map).

    However, this is not the case. I can simply set up one Player Input component on a global object (I chose EventSystem in my case) and it will gracefully handle both asset maps, and prevent the issue above.

    The implication here, though, is that if you have two scenes loaded additively, then the Player Input component cannot directly reference an object in another scene. You might expect to be able to resolve this by having a Player Input component in both scenes, but this is not the case (as it results in the issue above).

    I don't know what the recommended workaround for cross-scene Player Input is, unfortunately, so I'll just be working around it best I can (probably by clunky use of SetActive(true) on whichever Player Input I need at a given time).