[1.0.0-exp.8] Baker remove component and destroy entity

At 1.0 release, how can I remove redundant components in Baker since there’s no remove component and destroy entity API anymore?

1 Like

It’s a 2 part process. Bake then execute on baked data.
You need to do this in the second part via an ISystem (or SystemBase)

[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
internal partial struct YourSystem : ISystem

There’s also an attribute, [TemporaryBakingType], that can be used to pass data between Baker and your Systems that will be removed at the end and not make runtime

So you can create a

[TemporaryBakingType]
struct NoTranslation: IComponentData {}

public class NoTranslationAuthoring : MonoBehaviour {}

public class NoTranslationBaker : Baker<NoTranslationAuthoring>
{
    public override void Bake(NoTranslationAuthoring authoring)
    {
        AddComponent<NoTranslation>();
    }
}

[WorldSystemFilter(WorldSystemFilterFlags.BakingSystem)]
public partial struct NoTranslationSystem : ISystem {
    public void OnUpdate(ref SystemState state)
    {
        var ecb = new EntityCommandBuffer(Allocator.Temp);
        foreach (var (_, entity) in SystemAPI.Query<NoTranslation>().WithEntityAccess())
        {
            ecb.RemoveComponent<Translation>(entity);
        }
        ecb.Playback(state.EntityManager);
    }

    // ...
}
  • Code written in browser, may not compile
7 Likes

I’m using the code you have above, but using it to remove the Parent components that Unity adds. The system runs, but the foreach section doesn’t, even though I can see Entities with the RemoveParent BakingType component I added.

It looks like instead of this, I’d also be able to add a BakingOnlyEntity component to the parent entity (which is just an empty GameObject in the subscene used for grouping), but that component doesn’t seem to exist in my Entities package.