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 elpuerco63 · Dec 04, 2014 at 01:52 PM · orientationlandscapeportrait

IOS orientation loss on scene change

I have a menu scene that remains in landscape and another scene accessed from the menu scene using application.loadlevel() which can be all orientations.

I have attached the script below to a game object in both scenes with the flag set for landscape only for the menu and not set for the other scene and this works great on app start.

However if when in the second scene I am in portrait and return to the menu scene it displays the menu incorrectly as it remains in portrait rather than on menu load resetting to landscape only.

Am I doing this the wrong way?

Thanks

 public class DeviceOrientation : MonoBehaviour {
 
     public bool landscapeOnly;
 
     void Awake () {
     
         if (landscapeOnly) {
 
             // scene remains in landscape only
 
             Screen.orientation = ScreenOrientation.AutoRotation;
             Screen.autorotateToLandscapeLeft = true;
             Screen.autorotateToLandscapeRight = true;
             Screen.autorotateToPortrait = false;
             Screen.autorotateToPortraitUpsideDown = false;
         } 
         else {
 
             // scene allows auto rotation in all directions
 
             Screen.orientation = ScreenOrientation.AutoRotation;
             Screen.autorotateToLandscapeLeft = true;
             Screen.autorotateToLandscapeRight = true;
             Screen.autorotateToPortrait = true;
             Screen.autorotateToPortraitUpsideDown = true;
         }
     }
 }

 
Comment
Add comment · Show 2
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 SaraCecilia · Dec 04, 2014 at 03:37 PM 0
Share

Check out the solutions suggested in this post: http://blog.joachimbaur.de/?p=149

avatar image elpuerco63 · Dec 04, 2014 at 06:19 PM 0
Share

Thanks, but that is not the answer. I already have correct rotation and placement of background image and any gui elements when in the the menu scene. likewise the same is true for the second scene that allows full rotations.

The problem is navigating back to the menu scene the orientation code setting does not seem to apply

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by M-G-Production · Dec 04, 2014 at 07:04 PM

Hi elpuerco63!

Perhaps you could do so: this.DontDestroyOnLoad()

(you could change "this" with gameObject or whatever you want! "This" refers to the actual script)

(Read about it: http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html)

When a new scene is loaded, this script won't be destroyed and recreated.

Bests, Math

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 elpuerco63 · Dec 04, 2014 at 07:49 PM 0
Share

but surely if the menu scene is destroyed entirely when the next scene loads then is it not recreated anew when returning to it via application.loadlevel(menu) ?

And as such the orientation code should run?

avatar image M-G-Production · Dec 04, 2014 at 09:30 PM 0
Share

I think you should give it a try! I'm pretty sure it will work.

And yes, of course it should work! Or perhaps try switching Awake to Start! This could do it!

Please try it and reply back because I need to know something about the Awake fonction.

avatar image elpuerco63 · Dec 04, 2014 at 09:56 PM 1
Share

Hi, I'm trying that but getting weird results where stuff from second scene remain alive and appear over the menu?

Continuing to test ....

avatar image elpuerco63 · Dec 04, 2014 at 10:04 PM 0
Share

ok no more weirdness, but the suggestion re dont destroy doesnt work...:-(

avatar image
0

Answer by Owen-Reynolds · Dec 04, 2014 at 09:52 PM

This is from memory, from a "good enough" solution similar to this a year ago:

Setting orientation to AutoRotate only keys off of movement. It won't spin the screen now. I think you need to set orientation to a specific value, in order to force a change. Of course, then you need to set it back to autorotate, to enable the 180 flip.

Normally you don't have to worry about this, since the build settings force orientation to be legal on start-up, and most people never change autorotate. But, I think, for example, if you allowed any rotation in your build, and started the game end-up, the menu would be messed-up right away.

Comment
Add comment · Show 3 · 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 elpuerco63 · Dec 04, 2014 at 10:05 PM 0
Share

gonna try your thoughts now...

avatar image elpuerco63 · Dec 04, 2014 at 10:42 PM 0
Share

O$$anonymous$$ in Unity I have the project set to LandscapeLeft and this makes sure the menu scene appears only in landscape either left or right which is what I want.

When I load the second via the code runs to set rotation in all directions.

I have inserted this code in the menu scene start function which if second scene is portrait and returns to menu it does force orientation to landscapeLeft but it does not rotate to landscapeRight anymore and then if I then load second scene again the orientations are all to cock?

         if (Input.deviceOrientation == UnityEngine.DeviceOrientation.Portrait ||
             Input.deviceOrientation == UnityEngine.DeviceOrientation.PortraitUpsideDown) {
         
             Screen.orientation = ScreenOrientation.LandscapeLeft;
         }
 
avatar image Owen-Reynolds · Dec 05, 2014 at 03:08 PM 0
Share

I think this is where I stopped in my tests -- the specs got changed so we would never want portrait anyway.

Seems like the sequence would be : set Screen.orient to Left, wait a little bit for iOS to notice that and start turning, set Screen.Orient back to autorotate (how long to wait? 1 frame? As long as it takes to spin?)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Game support for landscape and portrait 0 Answers

Xcode 6 Orientation Issue 0 Answers

Difference between Screen.orientation - Input.deviceOrientation 2 Answers

Wrong Orientation Detected After Application Pause 0 Answers

iOS8 Screen Orientation Bug?? 0 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