Caching CommandBuilder in ECS

Hello,

Can I safely get my CommandBuilder in OnStartRunning() and Discard it in OnStopRunning() or do I have to get the builder every single frame?

I have noticed that the Editor crashes when I try this approach and I haven’t found anything about caching the builder in the docs, thus my question.

Hi

You have to get a builder every frame. It is internally cached.

With what error message does it crash?

If you want to avoid spending time building all drawing commands every frame, you can use a RedrawScope: GetRedrawScope - ALINE (the docs are a bit inaccurate in the current release, though. You don’t have to call redrawScope.Draw)

Thank you Aron! The RedrawScope sounds very promising. It seems exactly like the behaviour I was aiming for. e.g.: only draw (in my case) a grid once instead of issuing the same command every frame.

If you are interested I can recreate the crash and then look up the editor logs, since I am currently updating the builder every frame (to prevent the mentioned crash).

But as a quick example:

  1. Get Builder in OnStartRunning()
  2. Issue commands with the builder in OnUpdate() in multiple Jobs in every frame
  3. Dispose Builder in OnStopRunning() ----> Editor crash

Doing it the intended way “Get Builder in OnUpdate() → issue commands in jobs → Dispose(dependencies)” works completely fine!