I realized that I can just go through the Transforms of the prefab and get the entities, then in my conversion I can just manually create the LinkedEntityGroup. It’s not quite what I wanted, since I’ll need to manually create an identical GameObject prefab variant if I want multiple species to use the same object(no generic runtime copying). But it works alright and I can just Instantiate with little set up.
Final-ish conversion:
public override void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
base.Convert(entity, dstManager, conversionSystem);
dstManager.AddComponent<IsPlant>(entity);
Entity seedsDescriptionEntity = conversionSystem.GetPrimaryEntity(Seeds);
Entity rootsDescriptionEntity = conversionSystem.GetPrimaryEntity(Roots);
Entity plantDescriptionEntity = conversionSystem.GetPrimaryEntity(Plant);
dstManager.AddComponentData(entity, new SeedDescriptionEntity {Value = seedsDescriptionEntity});
dstManager.AddComponentData(entity, new RootsDescriptionEntity {Value = rootsDescriptionEntity});
dstManager.AddComponentData(entity, new PlantDescriptionEntity {Value = plantDescriptionEntity});
dstManager.AddComponent<IsSeed>(seedsDescriptionEntity);
dstManager.AddComponent<IsRoots>(rootsDescriptionEntity);
dstManager.AddComponent<IsPlant>(plantDescriptionEntity);
dstManager.AddComponentData(entity, LightPreference);
dstManager.AddComponentData(entity, SoilPreference);
dstManager.AddComponentData(entity, SpacePreference);
dstManager.AddComponentData(entity, SeedCountPerStep);
var speciesPrefabComponents = new ComponentTypes(new ComponentType[] {
typeof(Prefab), typeof(IsPlant), typeof(Age), typeof(Health), typeof(Fitness),
typeof(Rotation), typeof(Translation), typeof(Scale), typeof(LocalToWorld)
});
var plantPrefabComponents = new ComponentTypes(new ComponentType[] {
typeof(Prefab), typeof(IsPlant), typeof(SpeciesDescriptionEntity), typeof(DescriptionEntity),
typeof(LocalToWorld), typeof(LocalToParent), typeof(Parent)
});
var rootsPrefabComponents = new ComponentTypes(new ComponentType[] {
typeof(Prefab), typeof(IsRoots), typeof(SpeciesDescriptionEntity), typeof(DescriptionEntity),
typeof(LocalToWorld), typeof(LocalToParent), typeof(Parent)
});
// Construct completed species instances.
foreach(GameObject plantGO in Plant.InstancePrefabs) {
Entity plantPrefab = conversionSystem.GetPrimaryEntity(plantGO);
Entity speciesPrefab = conversionSystem.CreateAdditionalEntity(this);
dstManager.AddComponents(speciesPrefab, speciesPrefabComponents);
dstManager.SetComponentData(speciesPrefab, new Scale {Value = 1f});
dstManager.AddComponents(plantPrefab, plantPrefabComponents);
dstManager.SetComponentData(plantPrefab, new SpeciesDescriptionEntity {Value = entity});
dstManager.SetComponentData(plantPrefab, new DescriptionEntity {Value = plantDescriptionEntity});
dstManager.SetComponentData(plantPrefab, new Parent {Value = speciesPrefab});
Entity rootsPrefab = conversionSystem.CreateAdditionalEntity(Roots);
dstManager.AddComponents(rootsPrefab, rootsPrefabComponents);
dstManager.SetComponentData(rootsPrefab, new SpeciesDescriptionEntity {Value = entity});
dstManager.SetComponentData(rootsPrefab, new DescriptionEntity {Value = rootsDescriptionEntity});
dstManager.SetComponentData(rootsPrefab, new Parent {Value = speciesPrefab});
var speciesLinkedGroup = dstManager.AddBuffer<LinkedEntityGroup>(speciesPrefab);
speciesLinkedGroup.Add(new LinkedEntityGroup {Value = speciesPrefab});
foreach(Transform transform in plantGO.GetComponentsInChildren<Transform>()) {
Entity foundEntity = conversionSystem.GetPrimaryEntity(transform.gameObject);
speciesLinkedGroup.Add(foundEntity);
}
speciesLinkedGroup.Add(new LinkedEntityGroup {Value = rootsPrefab});
var speciesPrefabs = dstManager.AddBuffer<InstancePrefabs>(entity);
speciesPrefabs.Add(new InstancePrefabs {Value = speciesPrefab});
}
}