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 Lairinus · Jul 03, 2013 at 05:03 AM · guitexturerenderguistyle

Changing OnGUI Texture to be behind another (GUI Rendered off of same script, different instance)

I looked into GUI.depth but it looks like it has to be in a different script's OnGUI function to work. I am also using GUI Styles. Also looked into Texture Game Objects but that defeats the purpose of the Style

Is there any hope of getting one GUI Component to be in front of another if it's in the same script and without GUITexture GOs?

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

2 Replies

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

Answer by Jamora · Jul 03, 2013 at 06:12 AM

If I understood you correctly, you want to have control over which of your gui elements are drawn and when they're rendered? That is certainly possible. I'm currently working with a gui construct much like this:

 using UnityEngine;
 using System.Collections;
 
 public abstract class AbstractGUI : MonoBehaviour {
     
     protected bool displayGUI = true;
     
     /**
      * Sets displaying mode
      **/
     public void SetToDisplay(bool display){
         displayGUI = display;
     }
     
     /**
      * Called from the GUIManager's OnGUI.
      **/ 
     public void DisplayGUI(){
         if (displayGUI)
             ShowContents();
     }
     
     /**
      * Contains the implementation of the GUI
      **/
     protected abstract void ShowContents();
     
 }

All GUI elements inherit this abstraction.

I have a gui manager on a GameObject, who keeps a List of AbstractGUI which contains all instances of GUIs currently needed (the scripts(=instances) are added to the manager's GameObject). It goes though this list in its OnGUI(), giving me full control over which element gets shown and in what order.

Comment
Add comment · Show 2 · 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 Lairinus · Jul 03, 2013 at 06:21 AM 0
Share

I'll give you the credit-- I literally JUST finished coding something along these lines...

I made 10 different scripts called GUIDepth_1, 2, 3, (10) and I have all of the "Depth 1 components" in a list together, and every OnGUI a foreach iterates the "DrawComponent()" method.

Each script has a different GUILayer. Nothing is actually "called" unless allowed by the individual component.

Your way sounds easier in the long run. $$anonymous$$ine is easier when you're desperate and spent a few weeks working solely on GUI only to have your dreams crushed in the last 10 $$anonymous$$utes of coding.

avatar image Jamora · Jul 03, 2013 at 06:27 AM 0
Share

Remember to be careful with foreach. You can't do any changes to the list while iterating thru it. I made a coroutine that yield return new WaitForEndOfFrame(); before applying changes.

avatar image
0
Wiki

Answer by Quillicit · Jul 03, 2013 at 05:28 AM

I believe GUI.depth does in fact only work from other scripts. If you want one texture drawn on top of the other within the same OnGUI, the last thing drawn is what goes on top.

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 Lairinus · Jul 03, 2013 at 05:35 AM 0
Share

Thanks for your response.

Right now I'm creating all of my GUI objects from instances of the same base script called GUIComponent. When the script is set to "active" it's Rendered, else it is just skipped over.

Is that level of organization an impossible dream, or is there some way to make it happen?

avatar image Jamora · Jul 03, 2013 at 05:38 AM 0
Share

to clarify this answer, elements are drawn in the order they are in the script:

 void OnGUI(){
 //1st drawn element. This is behind everything else.
 //2nd drawn element, is in front of the 1st.
 //etc.
 //Last element is on top of everything.
 }
avatar image Lairinus · Jul 03, 2013 at 05:54 AM 0
Share

Yeah, and to clarify what I said:

10 GUIComponent scripts, each with OnGUI getting called 2x+ each frame == impossible to put one in front of another, even when utilizing all of the available GUI Code?

I was making dinky projects before this so I never really went deep into making multiple menus, and menu-ception so layers were never even needed.

Think I found a workaround with holding this same methodology... Sadly going to have to make another 10+ scripts...

After ~a year of using Unity, this is honestly the most ridiculous thing that I've found so far... guess I should feel lucky?

  • Also, will post my workaround if it works and there are others out there who can't bear the pain of writing dozens of scripts.

----- Ugh, refreshed the page by accident and posted an answer, my bad.

avatar image Quillicit · Jul 03, 2013 at 06:12 AM 0
Share

Glad you figured it out. It sounds like you can still do what you were initially looking to do, unless you want to shuffle individual textures from separate scripts. $$anonymous$$enu-ception it up.

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

17 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

Related Questions

is using OnPostRender to draw textures Pro only? 3 Answers

Understanding GUISkin/GUIStyle BackgroundImage and Border 2 Answers

Can i render a camera to a gui texture? 1 Answer

Render Texture to Full Quality Texture for GUI Use 1 Answer

GUI Style Issue-- Texture not changing 2 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