Hello!
So, Ive read in multiple places that OnGUI() Is laggy and or obsoloete I use it in my start menu and I am thinking about using it in an inventory or as a health bar is this a bad idea? What are your guys thoughts?
Thanks in advance.
Hello!
So, Ive read in multiple places that OnGUI() Is laggy and or obsoloete I use it in my start menu and I am thinking about using it in an inventory or as a health bar is this a bad idea? What are your guys thoughts?
Thanks in advance.
It is like 3 years obsolete so unless you are stuck on a version of Unity that is pre 4.6 than you should use the new system. I cant speak much performance but its just easier to edit and comes with more features.
OnGUI() is part of Immediate Mode GUI. It is no longer intended for use in the runtime. If you’re making runtime User Interfaces, then you should use the UI system introduced in 4.6.
It being obsolete has already been addressed, but I will also confirm the other question - it is definitely slow compared to other ways of rendering the UI. It does a LOT of unnecessary calculations, object creation/destruction, and draw calls. It’s especially poorly performing on mobile devices.
It is great for (and still recommended for) editor scripting, by the way.
Thank you @StarManta @LaneFox @TaleOf4Gamers_1 Is there any other methods that are good for drag and drop inventory?
simple answer = yes
I wonder when Unity is going to change all these obsolete things to ‘gone’. I’d really like to see that at some point. Maybe in Unity 6? I mean heck, 2 full versions later, I’d expect obsolete to finally reach purged status.
Or at the very least, have a way that builds with out these dependencies included.
I still use OnGUI for debug stuff. That’s about all it’s useful for nowadays to me.
I cant agree more, and they should remove Gameobject fine while ad it.
Isn’t the entire editor based off of OnGUI? If I’m not misunderstanding that, it would be very difficult to get rid of OnGUI.
He’s only talking about getting rid of it in the runtime, which would not be anywhere near as difficult. I’m pretty sure everyone still loves IMGUI for editor interface scripting.
Yes, so far as I know, the only way to create interactive user dialogs for an editor plugin/script is to use the OnGUI() method, which is why it still exists. For all in-game/runtime menus and such, you would want to use the inspector/canvas method… though that can be more painfull at times as well.
This.
And if people really need it for whatever reason, that’s why I suggested an option to not include the dependency if you’re not using it. Just like how assets in your asset folder if not referenced in any of the scenes don’t get built into the project, why are large portions of the library if unused getting included? (note, the build process probably couldn’t auto figure this out, but a toggle that allows me to include/exclude… I’ll deal with the bugs that arise as a result)