Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by peterc · Jun 17, 2015 at 03:23 PM · macsteamosxfocus

Why is my application pausing when starting on Mac through Steam?

When our game is run on Mac through the Steam client, it appears that the window immediately loses focus after creation, and, if it's not running fullscreen, is sent behind all other windows on the desktop. The player then has to cmd-tab to the game if it's windowed, or click on it if it's fullscreen, before the game registers any interaction.

The following events are coming through before the first update:

 OnApplicationPause(False)
 OnApplicationFocus(True)
 OnApplicationPause(True)

Oddly there's no OnApplicationFocus(False). If the game isn't set to "Run in Background", then we get just one call to Update() until the player manually restores focus to the app.

This only happens when running through Steam—running a build normally is fine. The current build uses Unity 4.6.6, but the same issue also hit us with 4.5 and 5.

Has anybody experienced similar behaviour? Is there any way to manually restore focus to a Unity app? I was thinking about writing an Objective C++ plugin to call the appropriate Cocoa API to restore focus, but that seems a little overkill.

Thanks!

Peter

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Adrian · Jul 07, 2015 at 11:34 AM 0
Share

We're seeing the same issue. Only happens with FullscreenWindow, not with CaptureFullscreen. We're seeing performance issue with CaptureFullscreen on some $$anonymous$$acs and therefore want to use FullscreenWindow. Had any luck fixing this yet?

avatar image peterc · Jul 07, 2015 at 09:44 PM 1
Share

We solved it, but not elegantly. :) I ended up compiling this .mm source:

 #import <Foundation/Foundation.h>
 #import <Cocoa/Cocoa.h>
 
 extern "C" {
     void activateWindow() {
         [[NSApplication sharedApplication] activateIgnoringOtherApps:TRUE];
     }
 }

into a native plugin, and calling the function from the first Update() call we receive. Works for a windowed or fullscreen video mode.

avatar image Stephen Lavelle peterc · Jan 25, 2016 at 10:14 AM 0
Share

made a build of this here, in case anyone else was confused. https://github.com/increpare/foregrounder_plugin/tree/master

thanks so much for the code snippit!

avatar image almo · May 12, 2018 at 05:57 PM 0
Share

I'm still getting this on 2017.4.2f2.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Adrian · Jul 08, 2015 at 09:34 AM

Update: See almo's answer. It's a clean solution while this is just a workaround.


I ended up with the following solution, not elegant either but doesn't require compiling and bundling a native extension.

Instead, I created a shell script and put it in the game's executable place. The shell script opens the actual game and then tries to focus it, trying a given number of times and checking if the game has focus.

To use, rename the game's executable in Game.app/Contents/MacOS to UnityPlayer, save the script below with the executable's original name and make it executable using chmod +x path… in the terminal.

 #!/bin/sh
 
 sleepinterval=0.1
 tries=10
 
 cd "$(dirname "$0")"
 appPath="$(pwd)/../.."
 
 ./UnityPlayer&
 
 sleep "$sleepinterval"
 
 script="POSIX file \"$appPath\" as alias equals path to frontmost application"
 while [[ "$(osascript -e "$script")" = "false" ]] && [ "$tries" -gt "0" ]; do
     let "tries-=1"
     open "$(pwd)/../.."
     sleep "$sleepinterval"
 done


Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image peterc · Jul 08, 2015 at 09:49 AM 0
Share

Ah, nice! Looks like the best solution for now.

avatar image spottedzebra · Jul 10, 2016 at 08:46 PM 0
Share

This solves the problem of app focus / opening in background, but now the S$$anonymous$$m Overlay won't come up at all . . .

avatar image
1

Answer by almo · May 13, 2018 at 02:00 PM

Got it.

In your launch options, Steam's default is:

Cognizer.app/Contents/MacOS/Cognizer

Don't do that. Just put

Cognizer.app

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Steam Overlay crashes the game on certain macs 2 Answers

Ludosity Steamworks Wrapper - Mac Exception 1 Answer

Mac OSX build from a Windows machine won't play on mac 2 Answers

Parse URL passed parameters on Standalone Mac build 2 Answers

Mac build crashes on start up 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges