When using ConvertToEntity (ConvertAndInject), how do I get the entity that was created?

When creating an entity from the conversion workflow ConvertToEntity with ConvertAndInject, is there a way to automatically retrieve the entity that is created from the conversion?

public Entity myEntity;

void OnWake() {
    myEntity = ...
}

If you implement the IConvertGameObjectToEntity interface, you will get a convert method with a reference to the created entity, an entity manager and a conversion system.

public class Example : MonoBehaviour, IConvertGameObjectToEntity
{
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
//do something with your entity here
    }
}
1 Like