playMaker

Author Topic: (SOLVED)PlaymakerGUI OnGUI massive performance impact  (Read 420 times)

SawyerK

  • Junior Playmaker
  • **
  • Posts: 79
(SOLVED)PlaymakerGUI OnGUI massive performance impact
« on: December 12, 2022, 09:59:54 AM »
Hi!

I have massive performance impact from OnGUI in editor and in build. I don't have much UI stuff in my fps game, menu, some floats on screen for the survival stats and when you hover over an item it shows it's name. I have huge lag spikes when pressing, releasing any button, even buttons that don't do anything, the worst is when I hold down a button (for moving a character of something) it creates this continuous lag spike.
I have no idea what causes this, or how this works.

Some help would be appreciated,
Thank you!
« Last Edit: December 19, 2022, 01:43:19 PM by SawyerK »

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #1 on: December 12, 2022, 10:34:52 AM »
This is borderline impossible to debug without deeper insight into the project structure and the FSMs involved. We also need more info on the Unity Version and the version of Playmaker, since afaik the way GUI is handled changed with Playmaker 1.9.0+. If you read up on "OnGUI performance" on google you quickly learn that many people have issues when using it without some sort of optimization concept. A few ideas nonetheless:

Have you tried narrowing down the problem?
Have you tried activating and deactivating certain parts of the UI Logic? If the problems disappear when something is turned off we can help you better figure out what exactly goes wrong. The Unity UI is pretty well known for being performance heavy - so if used improperly this can accumulate to big performance hits.

I can see compile errors in the lower left of your image
Are you sure that everything is running smoothly besides the OnGui ? Could there be something else interferring and resulting in excessive ongui calls?

Can you isolate the problem even further?
Does this problem occur when you put your FSMs / parts of the UI in an empty scene, with just a single button? Then you could share this with us for further debugging...

SawyerK

  • Junior Playmaker
  • **
  • Posts: 79
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #2 on: December 12, 2022, 02:06:37 PM »
Thank you for the quick reply!
The errors are only from when I fullscreen the game window, If i dont full screen there are no errors but the performance is the same, with onGUI eating it away.

Unity version: 2019.1.5f1
Playmaker version: 1.9.0

I have deactivated every UI and almost every gameobject in the scene even the Player controller, I only left the terrain and other gameobjects that don't have any fsm or script on them. This performance hit only occurs when I press or hold down any button, even buttons that don't do anything like I pressed Insert and there is the onGUI spike.
Also noticed that this onGUI performance hit gets bigger the more FSMs i have active on the scene. FSM that have no connection to any UI, GUI, or input button function whatsoever, with every UI element deactivated.
So basically the problem never disappears it's just gets bigger the more "stuff" is on the scene.
It's almost like the button press input is connected to every fsm and gameobject in the scene.
I don't know if this is how it supposed to work.
Something might have really messed up with the Input system?

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #3 on: December 12, 2022, 02:40:31 PM »
Can you try this:
https://docs.unity3d.com/ScriptReference/MonoBehaviour-useGUILayout.html

Some threads reference this as a possible culprit for performance hit.

https://answers.unity.com/questions/309130/how-do-i-prevent-the-gui-from-creating-lag.html

Turn off GUILayout

Luckily there is an action for this. Can you create a new GameObject, add an FSM to it and on Start use the action "GUILayout/Use GUI Layout" with the checkbox like in the screenshot below ?



Does this change anything?

SawyerK

  • Junior Playmaker
  • **
  • Posts: 79
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #4 on: December 12, 2022, 03:21:55 PM »
Hey,
The action didn't help sadly, no change.
Also it didn't disable the Enable GUI Layout in the PlayMaker GUI Script if that is what this action should've supposed to do.
Even when I manually disable it, the performance hit is still there when I press any button that doesn't do anything.
Disabling the other two options in the PlayMaker GUI Script doesn't do anything either.
When I completely disable the PlayMaker GUI Script the problem disappears but then of course I can't use the buttons in the menu.
Very strange that it's somehow connected to any input.


GUI Layout Disabled

PlayMaker GUI Script Disabled

Christoph

  • Beta Group
  • Full Member
  • *
  • Posts: 124
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #5 on: December 12, 2022, 11:16:06 PM »
Just curious: Is there a particular reason to not update playmaker to its latest version? Maybe even Unity to its latest 2021 LTS?

SawyerK

  • Junior Playmaker
  • **
  • Posts: 79
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #6 on: December 13, 2022, 06:28:05 AM »
Yes, I don't want to rebuild my game, it's way too big of a project, it would take years. Also there is an asset that don't work with more up to date Unity versions.

drown

  • Junior Playmaker
  • **
  • Posts: 58
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #7 on: December 14, 2022, 06:47:27 AM »
I guess then there is no trivial solution for your problem. The legacy UI system is terribly slow, that is exactly why Unity introduced the UI Workflows like UI Toolkit. At this point I am out of ideas, without a test scene to work on this would just be guesswork. So to not leave you without anything to work off of here are some final thoughts from my side:

Triple Check your code for bugs
We can look at screenshots as long as we want but we have not seen a single FSM you are using. On top, we have no idea how your UI is structured at all. I mean there is even an FSM on your Canvas in the hierarchy. Since we have no clue what you are actually doing we simply cannot debug and help properly. Our only ways to help are linking and quoting threads that have similar performance issues. So make sure you are not calling or sending out events on every button press or accidentally spawning dozens of listeners or whatnot.

Make sure you have optimized everything as well as possible.
https://unity.com/how-to/unity-ui-optimization-tips - Double Check this guide and make sure everything in there is applied.

Consider a third party UI solution
Since updating Unity and using a more performant solution is not an option, maybe consider rebuilding the UI with a third party solution like ngui. However that might not guarantee to solve your issues if they are caused by bugs in your state machines.

GermiyanBey

  • Playmaker Newbie
  • *
  • Posts: 1
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #8 on: December 15, 2022, 02:45:47 PM »
Right now I had the exact same problem and first I saw this thread. In my case, GUI.Repaint and PlaymakerGUI.ONGUI() {Invoke} were using 75% of performance (PlayerLoop: 65%, PlaymakerGUI: 49.5%) 

As solutions offered didn't solve my case, I tried adding this action (to an empty gameobject) "Enable GUI", and my FPS jumped from 30 to 85!

Action:
Enable GUI: OFF.

I hope it solves your case too.

SawyerK

  • Junior Playmaker
  • **
  • Posts: 79
Re: PlaymakerGUI OnGUI massive performance impact
« Reply #9 on: December 19, 2022, 01:30:20 PM »
Yes, Enable GUI works, so I basically only enable the GUI when the player is in the menu to make the buttons work, then when exit from menu disable GUI. It works, not perfect but much better then having -20 fps ingame :D
Thank you for all the help!

HaroldHancock

  • Playmaker Newbie
  • *
  • Posts: 1
Re: (SOLVED)PlaymakerGUI OnGUI massive performance impact
« Reply #10 on: January 24, 2023, 05:26:25 AM »
The same issue has been bothering me for a while as well. Thanks for sharing the solution for this issue. You made my day. I am also very happy because while searching for my issue solution online I also found https://studyclerk.com/pay-someone-to-do-my-homework website which solved my homework issue. Because over there I found someone who I can pay to do my homework and now I won't take too much time to write my essay assignments.
« Last Edit: January 27, 2023, 07:06:23 AM by HaroldHancock »