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 Hoeloe · Apr 21, 2014 at 10:25 PM · onguigraphics.drawtexture

useGUILayout preventing calls to Graphics.DrawTexture?

Hey, I've been looking for ways to increase the performance of my game. I've been doing some pretty expansive work with the GUI, making it resolution-idependant and so on, but it's started to become pretty intense.

It seems that OnGUI is being called a ludicrous number of times a second, so I read up on how to reduce the number of calls. Apparently, setting useGUILayout to false cuts the calls by half (and, indeed, my own tests shows this to be the case). However, I have an effect at one point of the GUI, which is the pause menu, where this causes problems.

My pause menu structure is quite simple. Since I don't have Unity Pro, I sample the screen to a texture using SetPixel. I then draw it at a quarter of the resolution, and blur it, using Graphics.DrawTexture. I then sample this smaller image again, and draw it across the whole screen, scaled up (again blurred) using another call to Graphics.DrawTexture. This gives a nice, blurred screen effect in the pause menu, and it all works find if useGUILayout is enabled.

If useGUILayout is disabled, though, neither of these called to Graphics.DrawTexture actually works, and I end up with an effect that is certainly not what I was looking for.

This is extremely odd to me, because this doesn't seem like it should happen. As far as I understand it, useGUILayout should have no effect on the Graphics class, and is solely designed to deal with built-in GUI functions (the only GUI methods I use are DrawTexture and DrawTextureWithTexCoords, both are working fine either way). I'm quite concerned by this, because it doesn't seem to make sense. Could anyone perhaps shed some light on what is actually going on?

Actually, I'm wrong here. Only the FIRST call to Graphics.DrawTexture does not work. The second one gets through fine. That is, if anything, even MORE confusing.

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 stevethorne · Apr 21, 2014 at 10:36 PM 0
Share

Why did you post this twice?

avatar image Hoeloe · Apr 21, 2014 at 10:39 PM 0
Share

Narrowed it down, I think, to when it takes the second screenshot. I have that running in a coroutine, using WaitForEndOfFrame to ensure everything is ready before continuing. This doesn't seem to work with useGUILayout disabled, so I'll try it another way.

Also, I didn't post it twice, I posted it once, then noticed a typo and edited it. It seems Unity Answers duplicated it when I edited it, keeping a version with the typo and the new edited version.

1 Reply

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

Answer by Hoeloe · Apr 21, 2014 at 10:46 PM

Fixed it! It seems that, with useGUILayout enabled, waiting for the end of a frame to draw a texture is valid. My guess would be because it allows the draw call to happen at the end of a layout phase, so it can be drawn during the repaint phase, or vice versa. I fixed this by moving a draw call out of a coroutine, and instead implemented it as a two-step draw, so that the preparation happens on one frame, and the execution on the next, rather that using WaitForEndOfFrame.

So, in short, don't use coroutines for drawing stuff, kids!

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

20 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

Related Questions

Drawing onto a render texture in OnGUI 0 Answers

Hiding OnGUI? 1 Answer

Android OnGUI Font size problem. 0 Answers

OnGUI button changes size for resolution, but text doesnt? 1 Answer

How to make a GUI window appear on clicking a game object 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