Hacking Unreal Engine AlembicImporter to provide a better error message regarding ngons

For now (as of UE4 4.26.1) Unreal Engine does not allow importing alembic with a face that has more than 4 vertices. Sadly, Unreal does not tell you which mesh of imported file is the one he complaints about.

In a complicated Alembic file, you can have thousands of meshes and just a few of them might have offending faces. An easy solution is to triangulate your mesh and try the import again. However, when you have a complicated model, triangulation can take considerable time or re-triangulating the whole model might not be an option at all. Figuring out which part of the mesh has the problem might be a big time saver.

An example of a ngon that has 5 vertices in Blender. The house is separated into three different meshes.

In this model example, we have a house that is consisting of 3 meshes: front face, inner side that is triangulated, and back face. Front and back face are ngons with 5 vertices.

Import dialog showing separate parts for import.

Our goal is to get the engine to report the name of meshes that cause an import problem, rather than just saying “Unable to import mesh due to a face consisting of # vertices, expecting triangles (3) or quads (4).”

An additional log message specifying name of offending mesh.

By finding the error message in the source code of Unreal Engine, we can find where is the message produced. We can go up the call stack to the frame (function) where we have information about mesh name. In this case, it’s a method `bool FAbcPolyMesh::ReadFirstFrame(const float InTime, const int32 FrameIndex)` located in file `AbcPolyMesh.cpp` of AlembicImporter experimental plugin.

We can simply add the following code snippet to achieve the desired effect:

After recompiling the engine, we get the following message:

We can see that `UE4Editor-AlembicLibrary.dll` was produced. All we need is to replace the DLL in our engine installation (hence the hack) and we are ready to go! There is no need to distribute to your team the whole engine because of this small change.

Don’t forget to add generated symbols for further debugging. Do not overwrite the `UE4Editor.modules` file as that would let UE4 know that our DLL is from a different build than the original UE4 installation.