I’m unable to write to the default CommandBuffer PostUpdateCommands in a ComponentSystem inside an extension method.
I’m wrapping this type of action (adding a State), in an extension method - SetState().
PostUpdateCommands.SetSharedComponent(salesOrder, new SalesOrderState { State = SalesOrderStates.WorkOrder });
// Extension Method
public static class EntityCommandBufferExtensions {
public static void SetState<TSharedComponent, TState>(this EntityCommandBuffer buffer, Entity entity, TState state)
where TSharedComponent : struct, ISharedComponentData where TState : Enum {
var stateObject = Activator.CreateInstance<TSharedComponent>();
var stateField = typeof(TSharedComponent).GetField("State");
stateField.SetValue(stateObject, state);
buffer.SetSharedComponent(entity, stateObject);
}
}
I use it like this:
PostUpdateCommands.SetState<SalesOrderState, SalesOrderStates>(salesOrder, SalesOrderStates.WorkOrder);
The code runs, but fails silently - the new state isn’t being updated.