Search Unity

Resolved New Input System detecting mouse clicks outside of Game view?

Discussion in 'Input System' started by Deive_Ex, Aug 29, 2020.

  1. Deive_Ex

    Deive_Ex

    Joined:
    Dec 30, 2014
    Posts:
    25
    The title should be pretty self explanatory, but I'll give a little more context.

    So, I 'm using the new input system and I doing a simple "move to mouse click position" system, where I get the current mouse position and shoot a ray from the camera to see where in the world I clicked. But, for some reason, when I click OUTSIDE of the Game View, it is STILL shooting the ray! This didn't happen with the old Input system!

    My code is basically as follows:

    if (Mouse.current.leftButton.wasPressedThisFrame)
    {
    RaycastHit hit;
    Ray ray = cameraController.cam.ScreenPointToRay(Mouse.current.position.ReadValue());
    if(Physics.Raycast(ray, out hit))
    {
    MoveToPosition(hit.point);
    }
    }


    So... Now I have this problem that I can't tweak values in the inspector (or interact with the editor in any way, really) without having my character move to my mouse, which makes things harder to test...

    Any help?
     
  2. Deive_Ex

    Deive_Ex

    Joined:
    Dec 30, 2014
    Posts:
    25
    Bump? This this is kinda of a big thing, isn't it? I can't really think of any reason of why the input system should detect clicks outside of game view...
     
  3. Deive_Ex

    Deive_Ex

    Joined:
    Dec 30, 2014
    Posts:
    25
    Okay, so, I think I found the solution.

    I delved more into the documentation of the new Input System and found that you can actually use it on Editor windows too, and the way it works is basically by doing what I did above.

    So, I thought, what if I create an action for my mouse click instead of doing it directly through code? And guess what? It works. By using an action istead, the clicks are only detected inside the game view and not in any other editor windows.

    While I couldn't find any mention of that in the documentation, after I read that you could detect clicks using the same cade as I did for editor windows, I just realized that maybe I should've done things differently.