Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
684 views
in Technique[技术] by (71.8m points)

unity3d - Unity: Application keeps running in background although Application.runInBackground is false

I'm currently developing some Unity project(this is my first one, I'm not familiar with Unity) and what bothers me is that breakpoints are still hitting when I minimize Unity editor window although I have Application.runInBackground == false so the app should be suspended while in background, but it is not ! Only the UI gets frozen and music stops while the actual code is continue executing. So, I'm basically wondering if this is general behaviour or this only happens when you're running in editor to allow debugging and in release builds code execution stops ?

question from:https://stackoverflow.com/questions/65940407/unity-application-keeps-running-in-background-although-application-runinbackgro

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Did you try changing it in the editor? go to Edit -> Project Settings -> Player. The inspector pane will now change to show the player settings. Look for the option that says "Run In Background" and uncheck it. From what I understand Application.runInBackground == false more of pauses it than stops the script from running. If your project is for mobile(or maybe just add this anyway, it might help),try:

RuninBackgorund is ignored for Android and IOS how you can see here

The only and efficient way to run in background on Android is through a Service. You can use OnApplicationPause method to get notified when the game pauses/unpauses.

public void OnApplicationPause(bool paused) {
if(paused) {
// Game is paused, stop service notifications.
} else {
// Game is unpaused, start service to get notifications
}

Here you have a nice tutorial about communication between android and unity


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...