Search Unity

Question Are bakers necessary? When is the best time to use bakers?

Discussion in 'Graphics for ECS' started by lgrammer, Feb 18, 2023.

  1. lgrammer

    lgrammer

    Joined:
    Feb 13, 2023
    Posts:
    23
    Can't I just create all my entities with the standard ECS stuff like this:

    public partial struct AddComponentToSingleEntitySystemExample : ISystem
    {
    public void OnCreate(ref SystemState state)
    {
    var entity = state.EntityManager.CreateEntity();
    state.EntityManager.AddComponent<Rotation>(entity);
    }

    }

    Am I understanding bakers correctly, and the only purpose is to convert regular game objects into ECS? The code below does the same as above just using a game object to start? They both can be ran with jobs/burst compiler yes? Both can have logic attached with systems?

    public class MyMonoBehaviour : MonoBehaviour
    {
    public float value;
    }

    public class MyBaker : Baker<MyMonoBehaviour>
    {
    public override void Bake(MyMonoBehaviour authoring)
    {
    AddComponent(new MyComponent {Value = authoring.value} );
    }
    }


    I'm about to rewrite a 2D procedural generation algo to DOTS and I can't decide how/when/if I should use bakers. Especially if the baker system will be modified for simplicity in the future anyways. Oddly enough I do like the structure of the code when using bakers more so I would like to use it when possible.

    Any advice on this subject is appreciated and thank you for your time.
     
  2. Arnold_2013

    Arnold_2013

    Joined:
    Nov 24, 2013
    Posts:
    284
    Bakers and Baking Systems are not at runtime. So all the processing is already done when the subscene is available.

    There are always multiple ways to do something, and especially with ECS the only thing that matters is what data is on what entity. So do what works and it will be fine, but the default methode is easier to get help with. Bakers are not going away, and after the major rewrite of all the code I like how they work.