Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question OnPointerEnter fires when another program is in front of the game

Discussion in 'Editor & General Support' started by dgoyette, Jun 8, 2023.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I just noticed that when playing a build of my game, OnPointerEnter events will fire as the mouse moves around the screen even if some other program (like Chrome) is on screen. For example, I alt-tab from my game to Chrome, and move my mouse around the screen (interacting with Chrome), but I'll hear the sounds that trigger from OnPointerEnter in my game.

    This happens when FullScreenMode is set to one of the Windows modes, such as FullScreenWindow, MaximizedWindow, or Windowed.

    Is there a way to prevent this? I can imagine going into every OnPointerEnter handler and adding a test of whether the game is currently focused, but that sounds like a nightmare, especially with 3rd party code. So is there a way to turn this off, so that the game doesn't handle OnPointerEnter when it's not focused?