Hey,
I’m having a hard time structuring my updates.
Begin/EndSimulationEntityCommandBufferSystem,
SceneSystem.UnloadScene,
SceneSystem.LoadSceneAsync
All of these can be used freely so there’s little guidance on when to do things. Up until now I’ve just picked more or less always picked Begin for the EntityCommandBuffer except in cases were things needed to be more structured. But when implementing level loading I’m now running into issues where I’m adding components to deleted Entities because they have cleanup components keeping them alive.
TL;DR; please give me some advice on a general rule to follow. Structural changes early or late in the frame? Is there some general rule or idea I’m not seeing?
Thank you very much ![]()
edit:
Or is the gist that the only real differences between those to is that there’s rendering in between (so really no difference at all) and that it’s more about the relative ordering of changes and updates?
edit2:
This is what GPT says, we live in truely good and/or bad times:
**Before the update phase** If you make structural changes before the update phase, you'll be working with a known set of entities and components throughout the update phase. This can help ensure consistency and make it easier to reason about the state of the game world during the update phase.
However, making changes before the update phase may not be appropriate for all types of changes. For example, if you're adding new entities that are dependent on the current state of the game world, making those changes before the update phase may not work. In that case, you may need to make the changes after the update phase.
**After the update phase** Making structural changes after the update phase can be useful if you need to create or remove entities based on the current state of the game world. For example, if the player collects a power-up that spawns a new enemy, you might want to create that enemy after the update phase to ensure that it spawns in the correct location.
However, making changes after the update phase may cause the game to briefly pause or stutter if the changes are significant. For example, if you're removing a large number of entities, that could cause a noticeable slowdown. To mitigate this, you may want to spread out the changes over multiple frames, or use a job system to distribute the work across multiple threads.
In general, the best approach depends on the specific needs of your game and the types of changes you're making. As always, it's a good idea to test and profile your game to ensure that the changes you're making don't negatively impact performance or introduce bugs.