I'm trying to bake a managed component (TestComponent) that starts in a disabled state, but I've run into an API inconsistency.
My Code:
class TestComponent : IComponentData, IEnableableComponent
{
public WeakObjectReference<GameObject> Test;
}
class TestComponentAuthor : MonoBehaviour
{
public WeakObjectReference<GameObject> Test;
class TestComponentBaker : Baker<TestComponentAuthor>
{
public override void Bake(TestComponentAuthor authoring)
{
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponentObject(entity, new TestComponent
{
Test = authoring.Test
});
// Set TestComponent to disabled
SetComponentEnabled<TestComponent>(entity, false);
}
}
}
The Baker.SetComponentEnabled<T> method doesn't accept class types (managed components), only structs. However, EntityCommandBuffer.SetComponentEnabled<T> has an overload that supports managed components:
// From EntityCommandBuffer - this works with managed components:
public static void SetComponentEnabled<T>(this EntityCommandBuffer ecb, Entity e, bool value)
where T : class, IEnableableComponent, new()
{
// implementation...
}
Is there a supported way to bake managed components in a disabled state?
I'm considering baking the component as enabled, then disabling it in a system on Start or on first update.
I need to use a managed component because of the GameObject references, but I want them to start disabled by default. Any help is appreciated!