If got a situation where I create a BlobAssetReference in a IConvertGameObjectToEntity and then in a separate IConvertGameObjectToEntity I want to add this to the Additional entities created.
This feels a little risky to me, is there a better way to handle this?
public class AuthoringA : MonoBehaviour, IConvertGameObjectToEntity
{
public static BlobAssetReference<Data> dataBlob;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
//..
dataBlob = BuildBlob();
dstManager.AddComponentData(entity, new BlobComponent {Data = dataBlob});
}
//...
[UpdateAfter(typeof(AuthoringA))]
public class AuthoringB : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
//..
var e1 = conversionSystem.CreateAdditionalEntity(this.gameObject, additionalEntities);
dstManager.AddComponentData(e1, new BlobComponent {Data = AuthoringA.dataBlob});
//..
var e2 = conversionSystem.CreateAdditionalEntity(this.gameObject, additionalEntities);
dstManager.AddComponentData(e2, new BlobComponent {Data = AuthoringA.dataBlob});
// ..
var e3 = conversionSystem.CreateAdditionalEntity(this.gameObject, additionalEntities);
dstManager.AddComponentData(e3, new BlobComponent {Data = AuthoringA.dataBlob});
//..
}
//...
I don’t know of the execution order of the conversions I think it’s done in the order the components are displyed on the inspector. I don’t think the update after work on IConvertGameObjectToEntity.
To solve your need I would try either :
make a singleton c# class that job is to make the blob and keep a reference to it until all conversion ended.
or
make a specific monobehavior component that just do the blob and that is required by both your ecs authoring components. (the blob would need to be create not in a IConvertGameObjectToEntity but in a method that run before Awake maybe ?)
Its weird, i can’t seem to break it, swapping components it still works, trying to forcing the blob to run last with
[UpdateAfter()] it still works , removing [RequireComponent(typeof())] it still works. The only way i get an error is if I remove the component. IM not sure what voodoo this is
EDIT :
wait doesn’t it all sit in the conversion world and them its all assembles in dst world … maybe using the serialize hash
It could be that the archetype generated for AuthoringA has higher priority than the archetype for AuthoringB. Because of that, AuthoringA would always execute first. I don’t know what rules dictate that though.
For blob generation, I always use a GameObjectConversionSystem and BlobAssetComputationContext. It is a lot of boilerplate, but it handles deduplication and fixes the execution order to something sensible.