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