I was glad to see
@ChrisIceBox implementing my
earlier performance requests. I have a similar request for a feature that probably very few people would ever use, except those that want to avoid any unnecessary overhead (and who are ahum.. are using their beloved adventure engine for any game genre).
So, after the earlier GC improvements, the AC menu system still eats about 25-30% of the frame generation time in my FPS intensive game, and this happens even when the menus are not updated in any way. I'm using AC+UGUI only.
To test if I can avoid that, I implemented a hack with a few lines of code in PlayerMenus.UpdateAllMenus() -method, which looks somewhat like this:
// Skip adding further menu overhead, if we choose to optimize current frame.
if (MyLevelManager.Inst.HackyHackOptimizeFrame()){
return;
}
// Non-hack code continues here
if (Time.time > 0f)
{
int languageNumber = Options.GetLanguage ();
A proper way to would probably not be "MyLevelManager.Inst.HackyHackOptimizeFrame()", but using a delegate method, I think? The purpose is that can we can return with TRUE or FALSE, allowing us to decide during each frame in our custom code if PlayerMenus.UpdateAllMenus() should allow to run till the end.
With this simplistic hack I saved those 20-30% of total overhead most frames. In my case the hack is active most of the time during normal gameplay, but not when the game is paused etc.
Comments
Indeed, updating the Menus each frame is certainly a large process - not least because of their co-dependance. Hovering over an Inventory item needs to update the text within a Hotpspot label, for example.
There is, however, already a means to prevent the UpdateAllMenus () function:
AC.KickStarter.playerMenus.SetMenuSystem (false);
That will disable the Menu system completely - if you're using AC's drawing system. If UGUI, it'll pretty much just prevent UpdateAllMenus from being run. Similar functions exist for the various input, movement, interaction etc systems.
While this is designed to be set at discrete moments (for example, at the beginning of a puzzle with a separate UI asset), rather than every frame, I suspect it could be placed in an Update() function to serve your purpose. It may not be as "neat" as a delegate, but introducing that while an alternative exists seems feature-creep to me - though I'll listen if it's not suitable after all.