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
4
Question by jjobby · Apr 28, 2011 at 12:40 PM · mobileperformanceongui

Should I avoid OnGUI for mobile development?

I have read many people opinions both from Unity forum and another forum. It seems the conclusion is that OnGUI is slow and can impact the performance. Well, the developers should be the one who know best about this issue. Why they don't improve it is really puzzling.

So basically, should I avoid OnGUI for iphone/android development at all costs? How much OnGUI elements (aka loop) which start to cause the performance hit? And what's the alternative way to draw GUI besides using spritemanager from Brady (I'm currently adapt a free spritemanager script to draw some buttons but it's really not convenient)?

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 dvr707 · Aug 06, 2016 at 03:04 AM 0
Share

Does this still hold true since its been 5 years the question was posted?

avatar image Owen-Reynolds dvr707 · Aug 06, 2016 at 03:06 AM 0
Share

See the manual: https://docs.unity3d.com/$$anonymous$$anual/GUIScriptingGuide.html It pretty much says to never use OnGui in a game.

2 Replies

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

Answer by Jessy · Apr 28, 2011 at 12:58 PM

Yes, you should probably avoid it for the time being, but it's dependent on how heavy the rest of your game is, and what devices you're targeting. It's potentially just fine for use with menus.

They are improving it. The progress was impeded by the not knowing whether Apple would enforce use of C++ for Unity scripting, last year.

There is no "convenient" alternative. For the time being, you just emulate the subset of UnityGUI that you need. That is, texture some quads, use efficient shaders, and use Text Meshes where you need dynamic text. I make heavy use of Rect.Contains, for Input.

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

Answer by Joshua · Apr 28, 2011 at 01:49 PM

Avoid it if you can, but for start/pause menus and a small HUD it's fine. The most important thing is that you really understand how the GUI system works, and that you make the OnGUI function do as little as possible.

This function is called twice every frame and once every event (!). Use it only for the actual drawing of the gui, but do all calculations somewhere else. If you'd make a health bar, the function that keeps track of your health would be inside the Update function for instance, and the OnGUI would just plug in the result. Or even better: the OnGUI would only be called if the result is different.

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 jjobby · Apr 28, 2011 at 02:56 PM 0
Share

How can I control OnGUI to only be called when the result is different? Isn't it automatically called in every frame/event?

avatar image Joshua · Apr 28, 2011 at 03:23 PM 0
Share

Yeah, you're right. Wasn't thinking there o.O.

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

2 People are following this question.

avatar image avatar image

Related Questions

Which one is better for mobile games many OnGUI function or one complex OnGUI function? 1 Answer

2d or 3d for better perform on mobile devices? 1 Answer

many prefabs. application Performance 1 Answer

Efficient way of having 1 draw call but allowing for debris physics [Mobile] 1 Answer

2D optimization help, im going crazy... 4 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