Keep Unity program working in background after device goes to sleep? - c#

I'm working on a Unity project that uses the device camera for AR purposes (I'm using AR Foundation). I currently have it set so that the device won't go to sleep (because I want it to operate for long-periods without user-interaction). Specifically, Screen.sleepTImeout = SleepTimeout.NeverSleep. If I didn't have this, then the device would go to sleep, and the program would stop functioning. Does anyone know if there is a way to keep the program working in the background after the device goes to sleep...similar to how music apps keep playing music? I've come up empty handed after a few hours of searching for a solution. Any help would be greatly appreciated!!!

Some people aren't finding this in more recent versions of Unity. But it's still there: In Player settings, under the section "Resolution and Presentation", you find "Resolution" and below that, there's "Run In Background".
This is only available for Web players and standalones (Anything Except IOS And Android Pretty Much), though (you won't find it when you have the iOS, Android or Flash tab selected.

Related

Hololens 2 tap and head movement works in Unity but not on HoloLens

While building an app for the HoloLens 2 in Unity 2019, I started using MRTK (Mixed Reality Toolkit). I repeatedly ran into problems where the app would work perfectly, as expected in Unity while running the game preview. Once I built and deployed the app to an actual HoloLens 2, however, it would not run correctly.
At first, the app was in a window similarly to here. Then, once the window was removed, the app moved as if it was stuck to the user's face instead of staying still as the user moved around it. Finally, the hand and arm recognition did not work.
I followed all of the code examples, and I know my scripts are working because they work as expected in Unity. So what is wrong? Why does the app work in Unity but not on the HoloLens itself?
This took a lot of poking around and trial and error because the issues were not directly related to my code, but rather the configuration of MRTK. These problems were because of the transition between the (now) legacy XR (Mixed Reality) system in Unity, and the new XR system. If you followed the setup on this page, you are using the legacy XR system and will need to transition to the new system. Follow the steps here to transition between the systems. Also make sure to add a TrackedPoseDriver to the camera, as described here.
Note that starting in Unity 2020, the new XR management system will be the only option in Unity, so new projects started on that version going forward should not suffer this issue.
Hopefully this experience helps others avoid the same issues!

Unity c# building game but not exe

So i know it sounds weird and the title is doesn't that much understandable so let me explain this first to you guys:
I have a unity virtual reality game which i build a couple of weeks now . And i uses a Leap motion device for my game and built it as an OPENVR supported on build setting. So i uses some 3rd party softwares like TrinusVR and SteamVR so that it will become a Virtual Reality even if it not built in .apk file . So when i try my game it was so very laggy(which is in my unity i've got only 50-100 draw calls and 30fps) and also it was jittery.
So i've come up with a solution . Using unity remote 5 it wasn't laggy and jittery but the problem is if i go spread my game out they can edit and mess up with my unity program .
So my question is how can i possibly make my unity project not editable when they open it on unity . Or is there any 3rd party software that i can try.
By the way i tried VRriftcat and SteamVr but still it was jittery and laggy.
Sorry for that long message. Hope someone give me some ideas .
EDIT: If i want to release this one then i'm having a problem in VRridge software and SteamVR.
The photo below shows my game.exe in my laptop using SteamVR and VRidge
and my Vridge software on my laptop is connected already on my VRidge APK on my phone. The problem occurs here now.
It my game doesn't render on my phone.
Help me guys . I tried your solution earlier so i tried it again and this happened

Can Unity's WebView play WebGL games?

I'm part of a team porting old WebGL / Cocos2D-JS games into Unity games, but since there's a lot of them, it's taking awhile.
So one of them asks, why not just use Unity's webview (as can be seen here) to show the WebGL games while the Unity versions are under construction?
I went ahead and tried that, running off a PC with Prepros hosting some web games created with Cocos2D, which is then accessed by a link in Unity.
Unfortunately, all I get is a black page (the same web view can open google just fine, for example).
Maybe I'm just doing something wrong, but I'd like to know if this is even possible in the first place.
The objective is to get Unity to play WebGL games on phones while the actual mobile versions of those games are under construction. Can it be done?

How to keep a media player going in mobile app?

So, I am looking to make a media player that is cross-platform (windows 10 + windows 10 mobile, XBOne, iOS, OSX, and Android), using C# (by far my most proficient language). I need it to remain playing in the background when the user is doing other things (for all but the XBOne). Ideally, I would like to use a cross-platform framework such as Unity, but if that's not possible, I need to know what steps I must take to make my app persist on each platform.
OSX/Windows 10 are easy, but I haven't been able to find absolutely any good information for Android/iOS especially. How does one keep a media player app going in the background on these? I see posts saying a media player that persists is doable, but they never say how.

Windows Phone 8 - 2 Background Audios Clash and both of the App terminates

around a week ago, I submitted an online Background Radio Streaming app for the Windows Phone store. The app was quite good (as I used the Emulator to test it, it was good on all the possible sectors) but when I submitted it for certification, it failed.
According the the error log, if someone is already playing a Music from Music + Video hub and then tries to open this app, both of the apps Crash and stop unexpectedly.
So far I understood, it is because the Music of Music + Video hub is also Background Music and for playing 2 Background Musics at the same time, the apps are Crashing. It can be some other reason but the described one seemed more logical to me.
So, is there anyone who can tell me how to change the state of the app of Music + Video hub? I want to pause or stop the app of Music + Video hub for the time being so that both of the states of the app are not same. In that way, the apps won't clash with each other in the background.
Can anyone help me in this regard?
Use gameHasControl to check for other BAP using music:
bool gameHasControl = Microsoft.Xna.Framework.Media.MediaPlayer.GameHasControl;
if (!gameHasControl)
{
MessageBox.Show("stopping other player"); // normally you should ask if to do that
BackgroundAudioPlayer.Instance.Stop();
}
Once it is Stopped, when you start your BAP, then old instance invokes Shutdown(), and your BAP will be new Instance, which you can normally use. The same is when your BAP is in memory and you start to play from Music+Video Hub.
Only watch out, because when you use XNA, you sometimes need to do:
FrameworkDispatcher.Update();
Otherwise your App will sometimes crash. Good luck.
EDIT - after comment
To make it work you need to add a reference to Microsoft.Phone.BackgroundAudio or use like this:
Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer.Instance.Stop();
BackgroundAudioPlayer is a Singleton which you are allowed to use - in this case - Stop it playing (of course give the choice to the User).

Categories