Application.isFocused is incorrect if another program has focus during launch

Steps to reproduce:

  • Launch your game (or switch to play mode in the editor)
  • Switch focus on another program before it starts up
  • Application.isFocused incorrectly reads “true” from here on out until you focus back to the game at least once, then it is proper when defocusing & focusing after that

Can anyone else reproduce this? Is there a workaround?

Can reproduce on Windows 10, Unity 2017.3.

Reproduced on Windows 10, Unity 2018.2.5f1

Awake() correctly detects Application.isFocused, but Start() always show True.


UnloadTime: 1.174717 ms
Awake: Application is focused: False
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
TinyBirdUtils.TinyLogger:Log(Object, Object) (at D:\GameDev\Unity\Toranneko\Assets\Scripts\TinyLogger.cs:20)
GameManager:Awake() (at D:\GameDev\Unity\Toranneko\Assets\Scripts\GameManager.cs:19)
 
(Filename: D:/GameDev/Unity/Toranneko/Assets/Scripts/TinyLogger.cs Line: 20)

Start: Application is focused: True
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
TinyBirdUtils.TinyLogger:Log(Object, Object) (at D:\GameDev\Unity\Toranneko\Assets\Scripts\TinyLogger.cs:20)
GameManager:Start() (at D:\GameDev\Unity\Toranneko\Assets\Scripts\GameManager.cs:36)
 
(Filename: D:/GameDev/Unity/Toranneko/Assets/Scripts/TinyLogger.cs Line: 20)

That feeling when you search for an answer to a year-and-a-half-old bug and only find your own post. :frowning:

This is reproductible with Webgl build and unity 2019.3

Any updates on this?
Application.isFocused is true after clicking the Play button but not clicking anything else afterwards while keeping the mouse cursor inside Unity window but NOT in Game window.
And even after that getting the mouse inside the Game window, clicking inside the game window will not trigger ApplicationFocusChanged true because it already thinks its isFocus, but in reality its not.
For Example the game will start with isFocused false if you click somewhere inside Unity after clicking the Play button but not being in the Game window.
It is just incovenient