Using Eigen (Third Party Library) in my plugin

Hey everyone,

I am working on a plugin and wish to use the included third party library Eigen (Engine->ThirdParty->Eigen) to handle the matrices. Fortunately I can see that there are a handful of other plugins that use Eigen (FullbodyIK, AlembicImporter etc) and the way in which they include the library is to include the module “Eigen” in the build file and then encase “#include <Eigen/Dense>” in some code to emit errors when Eigen is needed. When I do this myself though I have no such luck. It simply says it can’t find the library.

Does anyone have any ideas as to why this wouldn’t work? I feel I am missing a step when including Engine->ThirdParty libraries :confused:

1 Like

It’s seems like Eigen you get from “ThirdParty” in engine folder is incomplete and is missing some files. What helped me to solve exactly the same problem for UE4.27 is to download entire engine source code from https://github.com/EpicGames/UnrealEngine/releases , compile it and copy Eigen from there to my engine folder (I’ve attached it below, so you won’t need to recompile the engine; hopefully it will work for anyone else too).
Eigen_recompiled_427.rar (958.6 KB)

1 Like

Hey Andrej730!

This worked for me thanks! Admittedly though I found this same fix a few days following my original post and failed to update it. Sorry for that.

Interestingly in UE 5.0 you can now access the Eigen module. If anyone here upgrades their project you will have to remove Eigen from your project Third Party folder, or else your project may not package.

Thank you though, and apologies for not updating this post.

For anyone who want to add Eigen to your Unreal Engine plugin like me.

  1. Download and Extract Eigen:
    _ Download Eigen from the official website: 3.4.0 · libeigen / eigen · GitLab.
    _ Extract the downloaded file. You’ll get a folder named eigen-3.4.0.

  2. Organize Your Plugin Directory:
    _ Navigate to your custom plugin directory. This is typically located under your Unreal Engine project’s Plugins folder.
    _ Inside your plugin’s directory (e.g., YourProject/Plugins/YourPlugin/Source/), create a new folder named ThirdParty.
    _ Inside the ThirdParty folder, create a new folder named Eigen.

  3. Copy Eigen to Your Plugin:
    _ Copy the entire eigen-3.4.0 folder (from step 1) into the Eigen folder you created in your plugin. The path should look like YourProject/Plugins/YourPlugin/Source/ThirdParty/Eigen/eigen-3.4.0.

  4. Modify PluginName.Build.cs:
    _ In the constructor of PluginName, add the path to Eigen’s headers to PublicIncludePaths using Path.Combine(ModuleDirectory, "../ThirdParty/Eigen/eigen-3.4.0").

using UnrealBuildTool;
using System.IO;

public class PluginName : ModuleRules
{
    public PluginName(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        // Add the path to your local Eigen library
        PublicIncludePaths.AddRange(
            new string[] {
                Path.Combine(ModuleDirectory, "../ThirdParty/Eigen/eigen-3.4.0")
            }
        );

        // Other configurations for your plugin...

        PublicDependencyModuleNames.AddRange(
            new string[]
            {
                "Core",
                // Additional dependencies...
            }
        );
    }
}

  1. Include Eigen in Your C++ Code:
    _ In your C++ files where you want to use Eigen, include the header file using #include <Eigen/Dense>.
#include "YourHeaderFile.h"
#include <Eigen/Dense>

// Your C++ code using Eigen...

  1. Clean and Rebuild:
    _ Delete the Binaries and Intermediate folders in your plugin directory.
    _ Delete the Binaries, Intermediate, .vs, DerivedDataCache, Saved, YourProject.sln folders in your project directory.
    _ Right click on YourProject.uproject and choose Generate Visual Studio project files.
    _ Open YourProject.sln and click LocalWindowsDebugger.

Following these steps should successfully integrate Eigen into your Unreal Engine plugin. Good luck.



1 Like

I found the solution. We don’t need to download the Eigen library for inclusion in the plugin; we can simply use Unreal Engine’s built-in version for UE5.4. When you use the Eigen library from a download, it works in the editor, but after packaging the project and opening it, the project crashes when calling functions related to Eigen. I believe this is caused by Unreal Engine’s memory allocation being different from that of the Eigen library.
In YourPlugin.Build.cs:

// Use Unreal Engine built-in Eigen as a third-party dependency
AddEngineThirdPartyPrivateStaticDependencies(Target, "Eigen");

If you encounter an error during the project packaging related to unreachable code, you can suppress the error and continue compiling.

Also in YourPlugin.Build.cs:

// Suppress compiler warning C4702 for unreachable code
PublicDefinitions.Add("EIGEN_IGNORE_UNREACHABLE_CODE_WARNING=1");

To suppress the warning in your local code:

#pragma warning(push)
#pragma warning(disable : 4702) // Disable unreachable code warning

#include "Eigen/Dense"

#pragma warning(pop)

1 Like