Search Unity

Bug MacOS Unity Editor stealing focus constantly

Discussion in 'Editor & General Support' started by besttof, Feb 22, 2021.

  1. besttof

    besttof

    Joined:
    Jul 17, 2012
    Posts:
    29
    My Unity editor (this happens in multiple 2019 versions, up until 2020.2.1f1 on macOS 10.15.7) constantly brings itself to the foreground and it is driving me nuts. Doesn't matter if it is minimised, hidden or even on a different desktop, like the Spanish Inquisition it just appears when you least expect it.

    At first it seemed random, but I get the feeling it is related to multi touch gestures (i.e. scrolling, pinch zooming, etc) being intercepted when they shouldn't.

    Is there some obscure setting I enabled that causes this behaviour? Can I make Unity stop listening to mutitouch gestures (which would be great, because they make little sense as they are anyway) completely?

    Any tips, tricks or general help that stops Unity forcing itself to the foreground would be very welcome.

    edit: It is definitely a bug, whenever the cursor in a position where a tooltip would be shown, Unity steals the focus to show the tooltip.
     
    Last edited: Mar 3, 2021
    neonblitzer and dogboydog like this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Can you aggravate it? I mean use those gestures aplenty and see if it makes Unity fire off the "Look at me!" command...
     
  3. Deleted User

    Deleted User

    Guest

    I have this too. I see this in the editor log every time it happens:

    2021-03-02 09:26:20.624 Unity[53689:32268332] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
    2021-03-02 09:26:20.666 Unity[53689:32268332] CAMetalLayer ignoring invalid setDrawableSize width=0.000000 height=0.000000
     
  4. MangoFusion

    MangoFusion

    Joined:
    Jan 15, 2020
    Posts:
    2
    One big culprit of this: the project builder. If for example you are doing a WebGL build, several times during the insanely long build time the unity window will decide to pop up and interrupt you for no good reason.
     
  5. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    I get that too all the time.
    • If compilation has finished or an asset was refreshed, Unity always steals focus.
    • Sometimes Unity suddenly steals focus and I see there's some random curl error in the console.
    • Builder steals focus several times per second, which means that while Unity is building, the computer cannot be used for other tasks.
    • If Unity is behind another app, but my cursor is over a UI element that would show a tooltip, Unity steals focus in order to show that tooltip. Note that Unity was completely behind this other app's window.
    Could your problem be related to the last one I listed?
     
    besttof likes this.
  6. besttof

    besttof

    Joined:
    Jul 17, 2012
    Posts:
    29
    I'm pretty sure I have all of the above. For example, just now, I was typing in my IDE when Unity decided to steal the focus with a recompiling modal.

    I quickly tested the tooltip one, and yeah that could explain a lot. The fact that the tooltip has a delay on it before it activates, and thus steals focus, isn't making this easier.
     
  7. Deleted User

    Deleted User

    Guest

    In my case I don't think it's related to the tooltip thing. I always have my IDE and the editor in full-screen mode (MacOS) so I don't think they can be considered to be "over" each other, more like on separate screens. I tried triggering it manually by holding the cursor over an element with a tooltip in Unity and tabbing over to my IDE but couldn't get it to happen.

    I'm not sure, but I don't think this is happening in all projects. I spend almost all my time in one project, but sometimes I'll do a bit of work in an empty project and I've never noticed it happening there.

    Sometimes when it happens I see in the editor log that the Unity Project Id (of Unity Services) has been refreshed just prior, maybe that's related? It doesn't always do that, though. Unfortunately there's no timestamp on that log message so I can't tell if it happens at the same time as the focus steal. Anyhow, that could explain why it doesn't happen in a fresh project.

    I tried looking around the codebase to see if there is any code that runs in the background which might cause the editor to take focus, things like asset importers or similar. Didn't really find anything. If anyone has any ideas of specific Unity API methods that might cause the editor to take focus, I'm all ears.

    It would be really nice if someone at Unity could look into what causes the log message I pasted earlier in the thread, since that always happens together with the focus steal. Even if that error (invalid setDrawableSize) is not the cause of the issue, it might give a hint as to what kind of background operation is going on when the focus steal occurs.
     
  8. besttof

    besttof

    Joined:
    Jul 17, 2012
    Posts:
    29
    It got even weirder today. Unity was minimised and suddenly in totally unrelated apps (a file picker in the ImageImport app) Unity's tooltips started showing up! It didn't matter if Unity was in the background, minimized, on another desktop or even fullscreen in another space, holding the cursor on those locations made the tooltips appear over other applications.

    I find it very difficult to wrap my head around this.

    Out of curiosity, what IDE's are you using?
     
  9. Havokki

    Havokki

    Joined:
    Jun 28, 2015
    Posts:
    118
    I'm using JetBrains Rider and I can see it is sometimes fighting with Unity for focus. I write something, Unity suddenly steals focus, I write something more and Rider is able to steal focus back. It's as if Rider was still having the "keyboard focus" or whatever, but Unity forced its window to be in front.

    Oh, and my auto-refresh is off and even when I save files, Unity won't recompile until I press Cmd+R, so that is definitely not what was stealing focus in my case.
     
  10. besttof

    besttof

    Joined:
    Jul 17, 2012
    Posts:
    29
    Interesting, I use Rider too
     
  11. Deleted User

    Deleted User

    Guest

    Okay, I retract what I said earlier: I have the issue with Unity tooltips showing through other windows as well. It doesn't always happen, but I did manage to reproduce it on a couple of occasions, and it does cause the editor to steal focus.

    Oh and I also use Rider, but the issue happens in other applications as well.
     
    besttof likes this.
  12. Deleted User

    Deleted User

    Guest

    Bump.

    I've resorted to maximising the console window in Unity whenever I tab over to another application, since there's no tooltips inside the console window.
     
  13. cihad_unity

    cihad_unity

    Joined:
    Dec 27, 2019
    Posts:
    35
    Hello, I have this problem and sent a bug report regarding it.
    Unity team response is "cannot reproduce"
    This is the most irritating experience I've ever seen. Unity can focus even if it's minimized.
    I even removed all the pointer access from macos preferences but it didn't work.
    I've got to used to live with it. I move the whole window down to the screen so it can't steal focus from other apps...

    Edit: I use rider too (if there is a relation).
     
    Last edited: Mar 23, 2021
    besttof likes this.
  14. cihad_unity

    cihad_unity

    Joined:
    Dec 27, 2019
    Posts:
    35
    Update: I can confirm this happens if I connect external monitor.
    Edit: It was so in the beginning. Now it does it with built-in monitor too.
     
    Last edited: Mar 25, 2021
  15. vga256colours

    vga256colours

    Joined:
    Jun 24, 2019
    Posts:
    1
    Can confirm exactly the same focus-stealing behaviour running macOS 10.14.6, Unity 2020.2.2f1, Visual Studio for Mac 8.9.3 and SourceTree 4.0.1. It started happening in v.2019.* and has not improved with subsequent versions.

    I have never seen an app, in 15+ years of macOS use, aggressively steal focus from the currently active window before. It happens every 5-10 minutes, and I'm having a very difficult time trying to reproduce the behaviour because I cannot tell what is causing the focus theft.

    Update: I have now managed to replicate the behaviour reliably and consistently. It is caused by Unity's tooltip system reading the mouse cursor position when it should be *ignoring* the position because another program's window is overtop. I have made a video and will be submitting a bug report to Unity devs.
     
    Last edited: Mar 26, 2021
    Havokki and besttof like this.
  16. Chris_UprightGames

    Chris_UprightGames

    Joined:
    Oct 24, 2019
    Posts:
    4
    I can confirm this issue in Unity 2020.3.0f1 on MacOS Big Sur 11.2.3 and it's driving me insane.
    It's particularly bad when editing scripts in Rider, then Unity decides to steal the focus and you have to wait for the scripts to compile.
    Unity also tends to steal focus from Chrome when simply browsing a website.
     
  17. cihad_unity

    cihad_unity

    Joined:
    Dec 27, 2019
    Posts:
    35
    Any responses from Unity devs?
     
  18. Chris_UprightGames

    Chris_UprightGames

    Joined:
    Oct 24, 2019
    Posts:
    4
    Since we upgraded to Unity version 2020.3.6f1 the problem hasn't occured anymore.
     
    nhanc18 likes this.
  19. thomas-savysoda

    thomas-savysoda

    Joined:
    Dec 20, 2016
    Posts:
    8
    Still happening for us on 2020.3.15f1 when we save scripts in the Rider IDE and Unity recompiles. Honestly one of the most annoying bugs. Unity, for the sake of my sanity, please fix this!
    - Big Sur 11.2.2
    - Unity 2020.3.15f1
    - Rider 2021.1.3

    EDIT: So quickly after posting this I found the cause of the focus stealing on our end after some more debugging. I ended up finding that it was some custom editor windows causing the focus steal due to some
    EditorWindow.GetWindow
    method invokes not passing
    false
    for the
    focus
    param (which is default
    true
    ). After making those small changes we were no longer seeing the focus stealing issues. Although this may be unrelated to this issue, hopefully this could be the key to addressing this issue for some.
     
    Last edited: Jul 30, 2021
    Lars-Steenhoff likes this.
  20. wyattPD

    wyattPD

    Joined:
    Jun 17, 2022
    Posts:
    2
    For posterity, I'm on 2020.3.0f1, OSX Monterey, using Rider (same as above except slightly newer OSX and slightly older Unity). I use an external monitor for development (both Unity and Rider are on that screen).

    I'll investigate our usage of
    EditorWindow.GetWindow
    as thomas-savysoda described. I hit this bug more than 10 times a day and it's really annoying.