0
Answered

Where did so many updates and fixed updates come from?

Артём Фесуненко 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

I created this flow machine script for my buildings.

It does not contain any updates or fixed updates events.


I put this script on hundreds of buildings on my scene.
And for some reason they began to cause a huge load through the update and fixed update.


Here is the profiler on the same scene with disabled scripts on the buildings.


Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED

Thank you.

Satisfaction mark by Артём Фесуненко 3 years ago

For the test, I placed on the building an absolutely empty flow machine macro.
It calls on each object every frame - update and fixed update.
What the heck?!


Pending Review

In Unity, Update and FixedUpdate are implemented as methods on scripts. FlowMachine and StateMachine implement both. What they do in each of these methods is look in their graphs if there is an Update/FixedUpdate event, then trigger it. However, even if there is no event in the graph, they need to check at each update. This is also why you can add, for example, an update event during play mode.

There is no way to avoid implementing these methods, because they're the only event receivers from Unity. Notice that PlayMakerFSM also updates for every object on which you have it. The only way to prevent it would be to have 8 components:

  • FlowMachineWithoutUpdate
  • FlowMachineWithUpdate
  • FlowMachineWithFixedUpdate
  • FlowMachineWithUpdateAndFixedUpdate
  • StateMachineWithoutUpdate
  • StateMachineWithUpdate
  • StateMachineWithFixedUpdate
  • StateMachineWithUpdateAndFixedUpdate

You can see how this gets very confusing quickly! This is not something I want new users to have to think of.

In the future, I'm hoping to have Bolt compile to scripts and avoid this. 

In the mean time, what I can do is try to optimize how fast the event lookup occurs. I understand that taking such a high portion of your frame is not acceptable.

I'll try to include an optimization in the 1.1 cycle.

+3
Answered

I have an optimization in place for 1.1.3 (hotfix), should eliminate nearly all lag.