I am as of just a few moments ago as I just used it on a list of wheels.
This was what I have been using for the vehicle below, I originally set it up when the conversion system was first introduced a while back, but made the necessary changes to it the other day to get it working with the current api. Is there any sort of difference between doing it either way?
public NativeList<Entity> SpawnVehicle()
{
blobAssetStore = new BlobAssetStore();
var settings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore);
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
for (int i = 0; i < prefab.Count; i++)
{
var vehEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab[i], settings);
vehEntities.Add(vehEntity);
entityManager.AddComponentData(vehEntity, new VehicleEntity
{
entity = vehEntity
});
entityManager.AddBuffer<WaypointPathList>(vehEntity);
entityManager.AddComponentData(vehEntity, new VehicleTag());
entityManager.AddComponentData(vehEntity, new MovableTag());
entityManager.AddComponentData(vehEntity, new MoveSpeed());
entityManager.AddComponentData(vehEntity, new WaypointData());
entityManager.AddComponentData(vehEntity, new WPPathStatus { PathStatus = VehicleController.instance.pathStatus });
entityManager.AddComponentData(vehEntity, new WPGoalStatus { ReachedGoal = VehicleController.instance.goalStatus });
entityManager.AddComponentData(vehEntity, new WPMoveStatus { movementStatus = VehicleController.instance.moveStatus });
entityManager.AddComponentData(vehEntity, new SettingData
{
currentIndex = 1,
CurrentTurnSpeed = vehicleTurnSpeed,
DistanceFromWaypoint = distanceFromWaypoint
});
entityManager.AddComponent(vehEntity, typeof(Prefab));
#if UNITY_EDITOR
entityManager.SetName(vehEntity, $"Vehicle_{i}");
#endif
}
return vehEntities;
}
I put a script on the top level of the vehicle, then added each of the child wheels to the list and then used this:
public class WheelComponent : MonoBehaviour, IDeclareReferencedPrefabs, IConvertGameObjectToEntity
{
public List<GameObject> wheels;
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
for (int i = 0; i < wheels.Count; i++)
{
referencedPrefabs.Add(wheels[i].gameObject);
}
}
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
for (int i = 0; i < wheels.Count; i++)
{
var vehicleWheelEntity = new Wheel
{
entity = conversionSystem.GetPrimaryEntity(wheels[i])
};
var wheelSpin = new WheelSpin();
dstManager.AddComponentData(vehicleWheelEntity.entity, wheelSpin);
}
}
}
It seems to be working, but I am not sure yet if there are going to be any negatives to doing it this way, as the wheels are technically already part of the vehicle, which is getting converted with the top script, but then on the same prefab I have the second script to take care of the wheels. I am not sure of how else to do it without physically separating their hierarchy.