Log in or register to post comments

iPhone - screen gets black when changing rotation while Unity is paused

September 6, 2013 - 1:09am #1

I have a unity app, that uses Vuforia AR library. I extended this app with some iOs code. I wanted to be able to display my custom UIViewControllers sometimes instead of the main view controller that Unity uses. But I want to be able to switch back. I.e: I have a button that opens UIViewController with "About app" information and this controller then has "Exit" button to return to Unity controller.

This is my code for adding the new controller instead of the Unity View Controller:

self.unityRootController = self.keyWindow.rootViewController; // keep reference to the Unity Controller
self.keyWindow.rootViewController = controller; // display my own controller
 
// this pauses the unity and qcar -> so that QCAR doesn't try to recognize objects, when Unity Controller is not up
QCARUnityPlayer::getInstance().QCARPause(true);
UnityPause(true);

Then when returning from my own controller to Unity controller:

self.keyWindow.rootViewController = self.unityRootController; // return to Unity Controller
 
// start tracking with QCAR and unpause Unity View
QCARUnityPlayer::getInstance().QCARPause(false);
UnityPause(NO);
 

This works fine except one case, that's caused me to pull my hair ever since encountering it. My app supports changing orientation of screen in both Unity and ObjectiveC code. And this is the trouble: If I open my View Controller while the device is for example in Portrait Orientation, then turn the device to Landscape orientation, my controller gets correctly rotated. But if I at this moment want to close my custom view controller and return to unity controller, the screen gets black suddenly. After rotating the device to portrait orientation, the unity controller suddenly starts working as expected.

I'd like the unity controller to start directly after closing my custom view controller even if the screen orientation is changed. I suppose I have to add some code after I start again the Unity Player here: QCARUnityPlayer::getInstance().QCARPause(false); UnityPause(NO); // TODO: supposedly some code should go here, that fixes black screen

But I tried to find something in the AppController.mm, that is builded by Unity and I could not find anything, that would help me. I found few lines of unity code, that had the word "orientation" in it, but I tried to use that code and didn't help. Does anybody know, what should I do, please? Thanks a bunch :)

iPhone - screen gets black when changing rotation while Unity is

September 12, 2013 - 11:53pm #5

No luck :( Thanks for your answer. I guess it's not qcar at fault here, then, it's rather the Unity engine.

iPhone - screen gets black when changing rotation while Unity is

September 12, 2013 - 7:17am #4

The SetOrientation calls are what I meant, though still have no idea about the black screen

 

N

iPhone - screen gets black when changing rotation while Unity is

September 11, 2013 - 6:21am #3

Hi. Thanks for your input. I tried this code:

 

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    _curOrientation = orientation;
	QCARUnityPlayer::getInstance().QCARSetOrientation(_curOrientation);
    QCARUnityPlayer::getInstance().QCARPause(false);
    UnityPause(NO);

but that didn't help. I also tried:

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    _curOrientation = orientation;
    QCARUnityPlayer::getInstance().QCARPause(false);
    UnityPause(NO);
    QCARUnityPlayer::getInstance().QCARSetOrientation(_curOrientation);

But this also didn't help. Maybe you meant different QCAR methods?

iPhone - screen gets black when changing rotation while Unity is

September 11, 2013 - 4:40am #2

And this is the trouble: If I open my View Controller while the device is for example in Portrait Orientation, then turn the device to Landscape orientation, my controller gets correctly rotated

Have a look through the generated App files by searching for QCAR and you should find the calls that shadow the changes in orientation.  If to try to mimic this it may make a difference, though not sure it explains the black screen.

N

 

Log in or register to post comments