Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Bob-The-Zealot · Jul 07, 2016 at 07:38 PM · uicanvasscene-loading

Carry UI to new scene without moving the canvas

I have a group of UI elements that I want to persist between scenes. The UI elements are of the only canvas in the scene, so each time before there is a scene change, I unparent the UI elements and make them DontDestryOnLoad. After the scene changes, I reparent them to the present canvas.

My script for the UIs:

     public void BeforeChangeScenes()
     {
         transform.SetParent(null);
         DontDestroyOnLoad(gameObject);
     }
 
     void OnLevelWasLoaded(int level)
     {
         Canvas[] canvases = GameObject.FindObjectsOfType<Canvas>();
         transform.SetParent(canvases[0].transform);
         RectTransform rectTransform = gameObject.GetComponent<RectTransform>();
         rectTransform.anchorMax = new Vector2(1f, 0f);
         rectTransform.anchorMin = new Vector2(0f, 1f);
     }

BeforeChanceScenes is called before another script calls SceneManager.LoadScene

The unparenting, loading new scene, reparenting all succeeded. My problem is that after it reparents itself to the canvas it does not show up in the game or the scene. I can only see it in the inspector.

Comment
Add comment · Show 3
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 Bob-The-Zealot · Jul 09, 2016 at 07:38 PM 0
Share

Still need help :/

avatar image otomo · Jul 09, 2016 at 08:28 PM 0
Share

Are the UI Elements visible in the Scene Hierarchy?

avatar image Bob-The-Zealot otomo · Jul 09, 2016 at 08:58 PM 0
Share

Yes, they are visible in hierarchy but not game view.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by otomo · Jul 09, 2016 at 09:17 PM

I just tested this with a simple setup. It seems that UI Components get destroyed on Scene Load when they are not attached to a canvas. Even if you set them as DontDestroyOnLoad. I am not sure if that is a bug or intended behavior. A workaround would be to move the whole canvas to the new scene, move the UI Components to the new Canvas and destroy the old one, if you really need a new canvas in the new scene.

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 Bob-The-Zealot · Jul 10, 2016 at 12:17 AM 0
Share

I don't think they get destroyed if they are set DontDestroyOnLoad, since I still see it in the hierarchy, but I will try the new canvas idea.

avatar image
0

Answer by ahmadian · Dec 21, 2017 at 08:43 AM

You can have multiple canvases in a scene. Create a canvas only for those elements and make that canvas persistent using DontDestroyOnLoad. This way there is no need to destroy the old canvas or to rearrange the elements.

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

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

68 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 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 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 avatar image avatar image

Related Questions

Unity Cardboard bug on Nexus 6: U.I of previous scene is remained on view when new Cardboard scene is loaded 2 Answers

Main Menu Canvas and SetActive 1 Answer

Scene loading incorrectly 1 Answer

Using prefab in UI buttons and/or canvas? 1 Answer

Is there a clipping distance for UI elements? 1 Answer


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