Context
I am making a terrain generator that combines layers to generate terrain. Whenever a layer changes, I want to process it in my LayerChangedSystem and update the corresponding chunks.
The first time I perform a change, the layer GameObject is baked to an entity, the LayerChangedTag is added, and the LayerChangedSystem processes the layer. After that, the LayerChangedSystem removes the LayerChangedTag from all processed layers.
If I add a LayerChangedTag to the entity during the baking, I can successfully process the entity, but only once. After the system has disabled the tag, the baker seems incapable of enabling it again. Same problem if I try to add/remove instead of enable/disable. It only works once, even when all other components are updating fine.
Question
Is this a bug or an intended feature? Are there any better ways to mark entities as changed to process them in systems?
Below is the relevant code:
public class LayerBaker : Baker<Layer>
{
public override void Bake(Layer authoring)
{
Entity entity = GetEntity(TransformUsageFlags.Dynamic);
// Add other components
AddComponent(entity, new LayerChangedTag());
SetComponentEnabled<LayerChangedTag>(entity, true);
}
}
[WorldSystemFilter(WorldSystemFilterFlags.Editor)]
public partial struct LayerChangedSystem : ISystem
{
EntityQuery layerQuery;
public void OnCreate(ref SystemState state)
{
layerQuery = SystemAPI.QueryBuilder()
.WithAll<LayerChangedTag>()
.Build();
}
public void OnUpdate(ref SystemState state)
{
if (layerQuery.IsEmpty) return;
var layers = layerQuery.ToEntityArray(Allocator.TempJob);
// Process layers
for (int i = 0; i < layers.Length; i++)
{
// Disable LayerChangedTag because we are done processing the changed layer
state.EntityManager.SetComponentEnabled<LayerChangedTag>(layers[i], false);
}
layers.Dispose();
}
}