I am wondering everyone’s opinion on the best way to handle a games GUI. My game is made up of various objects like thrust, weapon system, target system, etc. My question is whether I should have each system handle its own related GUI, or should I have one object that handles everything? If I have one object that handles everything, should it request its info every frame like “thrust.getThrottle and targetSys.getTarget” or should each system get a handle to the GUI and send its updates only when something changes? I’m wondering how everyone else handles a complex GUI/HUD.
Wow, this is the first time I haven’t gotten an answer, I guess that means I was either to vague or the question was too dumb :lol: . I do have to say though that support on this form has been beyond good. I guess a simpler question would be, How slow is it for my GUI to make lets say 15 functions calls every update? These would be just something like thrust.getThrottle which would return a simple int. Is this something I would have to worry about when making a PC or Web Game?
if you use unity gui its updated every single frame, no control there for you at all.
if you develop your own system its up to you what makes more sense.
event based updating is more common though.
Use the GUI to display info not get it. That is what Update, FixedUpdate and LastUpdate are for. You don’t want to get your display bogged down if it can’t get some data. Also back to your question I try to seperate as many of the functions as possible. Primary reason is for reuse by other functions in the project and other projects down the line.
It can sometimes end up being 30 function calls, as OnGUI() is often executed multiple times a frame.
Like others have said, try and have the data already available to OnGUI() instead of doing intensive calculations or calls within it. For example liberal use of find api’s inside OnGUI() will bring your game to a crawl.
Standard practice around here is a game manager singleton having ready access to it all, which you can then reference in your script containing OnGUI(). If your game is rather simplistic in nature, you can just cache references to important gameobjects and scripts in Start().