Unresolved external symbol FSlateColor (including fix)

Hello everyone, I’m adding this here in case anyone has the same problem in the future.
Long story short: I needed a FSlateColor](FSlateColor | Unreal Engine Documentation) as a parameter for a function and as a class member (for use with SetColorAndOpacity on a simple UTextBlock widget),
Included the necessary Styling/SlateColor.h
But when compiling (4.24) I was met with linker errors:

[FONT=courier new]error LNK2019: unresolved external symbol “__declspec(dllimport) public: __cdecl FSlateColor::~FSlateColor(void)” (_imp??1FSlateColor@@QEAA@XZ) referenced in function “public: __cdecl TArray<struct FSlateColor,class TSizedDefaultAllocator<32> >::~TArray<struct FSlateColor,class TSizedDefaultAllocator<32> >(void)” (??1?$TArray@UFSlateColor@@anonymous_user_e71e0d8a?$TSizedDefaultAllocator@$0CA@@@@@QEAA@XZ)

Which was strange since this does not seem to always be an issue, maybe something to do with conversion between FSlateColor and FLinearColor …?
I fixed it by adding the SlateCore module to Build.cs

Now my question is, why would this be needed? Simply including the header should be enough (and really, the SetColor function should take a FLinearColor, or simply four 0-255 floats)

6 Likes

Unreal Engine is separated into a lot of Modules, if you want to use a type which is declared in another module you need to notify the build system that you “depend” on that module to build your own module, and without the module you cannot include the header (well you can, but you’ll get linker errors)

FSlateColor is a slate type and therefore lives in the SlateCore module.

You can usually find out what module a class belongs to by looking at the header and finding out which ###_API it uses. For example, many UMG types have the UMG_API specified, common engine types use ENGINE_API etc etc.

3 Likes