Bake vs Entity Manager for a list of pure data?

EDIT: The answer seems to be use the CreateAdditionalEntity

Method CreateAdditionalEntity | Entities | 0.17.0-preview.42

Hello gang,

I have a road asset (Easy Roads 3D, awesome, HIGHLY recommend!) that has road/connection/lane data. I have distilled this down to just Lanes: Lane identity, points (a list), connectedLanes(a list)

I did this so at runtime an Auto just has to get the next Lane. Easy, quick, fine.

But here’s the thing, I know authoring/baking is the new method, but what I don’t know how to do is take this existing Lane data and convert it to entities via Baking. I can do it via the Entity Manager, but if Baking is better, then I want to learn the better/correct way.

Below is my current bake code, but it’s throwing an exception at the SECOND time through the loop as the GetEntity is getting the same entity as the first one. So yea, I get this… but how am i SUPPOSED to create some pure data entities?

public class TrafficLaneAuthoring : MonoBehaviour
{
    public List<TrafficLane> trafficLanes = new List<TrafficLane>();
}

public class TrafficLaneBaker : Baker<TrafficLaneAuthoring>
{
    public override void Bake(TrafficLaneAuthoring authoring)
    {
        //var entity = GetEntity(TransformUsageFlags.Dynamic);
        //var dynamicBuffer = AddBuffer<LaneSpawnerComponent>(entity);

        for (int i = 0; i < authoring.trafficLanes.Count; i++)
        {
            var laneEntity = GetEntity(TransformUsageFlags.None);
            AddComponent(laneEntity, new LaneTag { });
            AddComponent(laneEntity, new Identity { value = authoring.trafficLanes[i].laneIdentity });
            //dynamicBuffer.Add(new LaneSpawnerComponent { prefab = laneEntity });
        }
    }
}

Thanks

Are you looking for CreateAdditionalEntity()?

If not, you may need to specify what you want your end data to look like.

1 Like

Thanks, good note.

The end result is just a bunch of entities:
var laneEntityArchetype = entityManager.CreateArchetype(
typeof(LaneTag),
typeof(Identity),
typeof(LanePoints),
typeof(ConnectedLanes)
);

The Tag is empty, identity is IComponentData and the other two are IBufferElementData. So it’s not a matter of how to create these entities, as I can do that in Entity Manager, but because the GetEntity method in Bake returns the same entity the second, and all subsequent iterations I am obviously doing something wrong in my attempt to bake these entities.

Then yes, you are looking for Method CreateAdditionalEntity | Entities | 1.2.3

1 Like

It seems “CreateAdditionalEntity” is what I needed

https://docs.unity3d.com/Packages/com.unity.entities@0.17/api/Global-Namespace.GameObjectConversionSystem.CreateAdditionalEntity.html