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
1
Question by Xarbrough · Jan 07, 2016 at 07:06 PM · c#uicanvasonguisorting order

4.6 UI sort order in fornt of IMGUI/OnGUI possible?

Is there a way to display a new UI (post Unity 4.6) canvas in front of old OnGUI elements? I've tried setting the OnGUI elements to sortOrder = 1 and the new ones to 1000, but OnGUI still draws on top of everything else.

I'm using a canvas for debugging and want it on top of everything else, but some other tools still draw old OnGUI debug info etc, that's why I have both currently.

Comment
Add comment · Show 1
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 xsc14 · Feb 21, 2017 at 04:27 PM 0
Share

Have you solved it?Same problem occurred to me : (

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Feb 21, 2017 at 06:02 PM

Yes you can draw the new UI on top of the old IMGUI. You just need to setup your new UI properly and render it manually from inside OnGUI.

The repaint event of the OnGUI callback is pretty much the last thing that is rendered. It will fire when all cameras have finished rendering. That's why you have to do the following:

  • Setup your canvas to be "screenspace - Camera" and create a dedicated UI camera for this canvas. You might want to use a seperate layer for that UI stuff and set the camera cullingmask accordingly.

  • Make sure you assign that camera in your UI canvas.

  • Make sure you disable the camera and set it's clearflags to "Depth only"

Inside OnGUI you can now manually render your UI camera after your other OnGUI stuff::

 public Camera UICamera;
 void Start()
 {
     UICamera.enabled = false;
 }
 void OnGUI ()
 {
     if (GUI.Button(new Rect(10,10,300,200),"Test Button"))
     {

     }
     if (Event.current.type == EventType.Repaint)
     {
         UICamera.Render(); // this will render the new UI
     }
 }
 

Note that if you need interactive elements in both UIs you have to take care yourself of which should get the input. The new UI uses the new Eventsystem while OnGUI directly processes input usually around the time when Update is called.

Though pure visual UI should work just fine that way.

If you have multiple scripts that use OnGUI and you want the new UI on top of all of them you simply would render the camera from a seperate script with OnGUI callback that is ensured to run last / is on top.

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 Bunny83 · Feb 21, 2017 at 06:02 PM 0
Share

ps: I've tested this approach and it works.

avatar image Xarbrough · Feb 21, 2017 at 06:06 PM 0
Share

Yes, thanks. I've seen this approach used by another dev while hacking a old project and mixing with the new UI system. Seems to work fine for those special cases.

avatar image xsc14 · Feb 21, 2017 at 11:58 PM 0
Share

Thanks for sharing! Great help to me! : )

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

62 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

Related Questions

How do I obtain children on UI canvas text 0 Answers

Trying to place an UI Canvas Image next to another UI Image 1 Answer

Is there a way to make a Texture2D screenshot that ignores the canvas? 3 Answers

CanvasGroup.alpha hides the UI in Scene view but not in game view. 1 Answer

UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 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