Someone can say how to make such a construction work? Currently returns UnityExtension. Well, or advise how easy it is to move a part of the non-MonoBehaviour code into a separate thread.
UnityException: get_canAccess can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
private async void Awake()
{
Mesh protoMesh = gameObject.GetComponent<MeshFilter>().mesh;
SelfMesh = await InitMeshAsync(protoMesh);
}
protected async Task<CustomMesh> InitMeshAsync(Mesh protoMesh)
{
return await Task.Run(() => new CustomMesh(protoMesh.vertices, protoMesh.triangles));
}