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

Filip Sivák
3 min readMar 20, 2021

--

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:

if (FirstSample) {
/* ... Some Code ... */
}else {
const FText MeshName = FText::FromString(GetName());
const TSharedRef<FTokenizedMessage> Message = FTokenizedMessage::Create(EMessageSeverity::Error, FText::Format(LOCTEXT("FoundNGon2", "Wrong mesh {0}."), MeshName)); FAbcImportLogger::AddImportMessage(Message);
}

After recompiling the engine, we get the following message:

1>------ Build started: Project: UE4, Configuration: Development_Editor x64 ------1>Using 'git status' to determine working set for adaptive non-unity build (C:\Users\filip.sivak\workspace\Repos\UnrealEngine).1>Invalidating makefile for UE4Editor (AbcFile.cpp modified)1>Building UE4Editor and ShaderCompileWorker...1>Using Visual Studio 2019 14.28.29334 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29333) and Windows 10.0.18362.0 SDK (C:\Program Files (x86)\Windows Kits\10).1>[Adaptive unity build] Excluded from AlembicLibrary unity file: AbcPolyMesh.cpp1>Building 4 actions with 24 processes...1>  [1/4] Module.AlembicLibrary.cpp1>  [2/4] UE4Editor-AlembicLibrary.lib1>     Creating library C:\Users\filip.sivak\workspace\Repos\UnrealEngine\Engine\Plugins\Experimental\AlembicImporter\Intermediate\Build\Win64\UE4Editor\Development\AlembicLibrary\UE4Editor-AlembicLibrary.lib and object C:\Users\filip.sivak\workspace\Repos\UnrealEngine\Engine\Plugins\Experimental\AlembicImporter\Intermediate\Build\Win64\UE4Editor\Development\AlembicLibrary\UE4Editor-AlembicLibrary.exp1>  [3/4] UE4Editor-AlembicLibrary.dll1>     Creating library C:\Users\filip.sivak\workspace\Repos\UnrealEngine\Engine\Plugins\Experimental\AlembicImporter\Intermediate\Build\Win64\UE4Editor\Development\AlembicLibrary\UE4Editor-AlembicLibrary.suppressed.lib and object C:\Users\filip.sivak\workspace\Repos\UnrealEngine\Engine\Plugins\Experimental\AlembicImporter\Intermediate\Build\Win64\UE4Editor\Development\AlembicLibrary\UE4Editor-AlembicLibrary.suppressed.exp1>  [4/4] UE4Editor.target1>Total time in Parallel executor: 38.81 seconds1>Total execution time: 68.02 seconds========== Build: 1 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========

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.

--

--

No responses yet