BeginSimulationEntityCommandBufferSystem vs EndSimulationEntityCommandBufferSystem

Is there any logical difference between BeginSimulationEntityCommandBufferSystem and EndSimulationEntityCommandBufferSystem? It seems they are logically same. Should one be preferred over other? What’s the purpose of having the both of them?

One run when at the beginning of the SimulationSystemGroup, and another at the end. You may want to show score feedback on the same frame that the player scored, thus requiring you to use the EndSimulation one, or you may want to delay an Entity creation to the next frame, thus using the BeginSimulation one

Thank you for your response! But why would I delay an entity creation and not do it in the same frsme? Also, I thought that SimulationSystemGroup is independent from PresentationSystemGroup, that should be used for presentation. And I can do nothing in between End and Start, correct? Since every system is between Start and End… Unless Presentation systems, that take that interval between End and Start of simulation? Or are those parallel?

You mean BeginSimulationEntityCommandBufferSystem and EndSimulationEntityCommandBufferSystem
or EndPresentationEntityCommandBufferSystem and BeginSimulationEntityCommandBufferSystem?

If the later, I would say that it is just for organization purpose (like running things on Update vs LateUpdate, or Awake vs Start.

About why to delay entity creation, Event system running close to EndSimulation may want to create entities on the BeginSimulation of the next frame (for example: to have the TransformSystemGroup to apply its logic before presenting the entity).

No, it was about BeginSimulationEntityCommandBufferSystem and EndSimulationEntityCommandBufferSystem. So, why would we need EndSimulationEntityCommandBuffer then? Is there a case where we’d need to spawn anything before the next Simulation frame for any purpose?

Yes, if you want it to already exist in the PresentationGroup at the same frame you will want to use the EndSimulation, or else the user will have one frame delay. The major downside I see of using the EndSimulation is that you need to calculate the LocalToWorld manually, so there are some tradeoffs to consider (and why I find myself usually delaying the spawn one frame, so that I can take advantage of the TransformSystemGroup).

if I’m not mistaken, when you scheduling some changes in some ECB system BEFORE it, the changes will be applayed in the same frame (for example you add commands to end sim buffer inside simulation group). And when you want to do changes AFTER some ECB system, changes will be applayed only in the next frame (for example when you add command to begin sim buffer inside simulation group).
You can get benefit using both systems to separate commands that mutate data and commands that delete entities to ensure that you will never try to modify something that already destroyed

2 Likes

Cool, awesome, thanks everyone!

In most cases I use Begin…EntityCommandBuffer from the next group relative to the system I am in. This way sync point will be delayed and some code in Update and LateUpdate could run in parallel to the jobs (if I understood this correctly).

I usually spawn new entities in BeginSimulationCommandBufferSystem, and I destroy them in EndSimulationCommandBufferSystem.

If I didn’t, freshly spawned Entities would be picked up by the presentation system before the simulation could do things with them, and destroyed entities would be presented one more time before they actually got removed.

5 Likes