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
0
Question by Nanako · Apr 21, 2015 at 10:51 AM · applicationfocus

Is there a way to detect when the game window has focus?

I'd like to know when my game window has focus, and is capturing inputs.

Just spent a minute perplexed why my script wasnt reading the mousehweel movement, before realising i had to click in it. I'd like to add a visible indicator/error message to let me know when its not focused.

how?

Comment
Add comment
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

2 Replies

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

Answer by HarshadK · Apr 21, 2015 at 10:55 AM

To know this from your script you can use: MonoBehaviour.OnApplicationFocus(bool)

Comment
Add comment · Show 4 · 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 Nanako · Apr 21, 2015 at 11:20 AM 0
Share

hooray. This works

having it as a seperate function/monobehaviour is mildly annoying, is there any more compact method? like a function call, or a variable to check/ is i necessarf to maintain that myself?

avatar image HarshadK · Apr 21, 2015 at 11:24 AM 0
Share

You can actually do this yourself.

Just create a script with a singleton pattern that sets a variable to true or false based on the state of focus on game window. You can now check this variable to see if the game window has focus or not from any other script.

avatar image Nanako · Apr 21, 2015 at 11:42 AM 0
Share

yes, i'm well aware that i can do that. I'm just asking if it's already done anywhere internally. This seems like a variable that the application would want to keep track of naturally, no?

avatar image HarshadK · Apr 21, 2015 at 11:51 AM 0
Share

There is one such variable but it is for editor window and it returns the window with keyboard focus: EditorWindow.focusedWindow

I do not know of any variable that is exposed in public API for OnApplicationFocus. :-(

avatar image
7

Answer by matijas_05 · Oct 21, 2017 at 03:12 PM

Use "Application.isFocused"

Comment
Add comment · Show 1 · 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 Edy · Apr 15, 2019 at 08:25 AM 0
Share

Best answer

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

22 People are following this question.

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

Related Questions

How to distinguish Firebase Push Notification received in Background and when App open 0 Answers

Keeping Unity Focused 0 Answers

Problem with Unity GUI ! 0 Answers

C# Tooltips through multiple windows 1 Answer

Remove Focus From InputField 2 Answers


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