Possible to derive from UImage ?

I am trying to extend the functionality of the UImage widget, only a simple change to autoset the brush based on an id property.

However whenever I try to derive my own class from UImage I get a wall of linker errors, the 1st of these is claiming unresolved symbol for UImage::UImage. From this I assumed I had to implement a constructor in my own class and include the UImage constructor in the chain passing the FObjectInitializer into that. Doing this makes no difference at all to the linker errors!?

Am I missing something?

UCLASS()
class FLUIDMOVEMENT_API UButtonIcon : public UImage
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FName actionId;

	UButtonIcon(const FObjectInitializer  & objInit) : UImage(objInit) {};
};

and the error (snipped) is:

ButtonIcon.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl UImage::UImage(class FObjectInitializer const &)" (__imp_??0UImage@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function "public: __cdecl UButtonIcon::UButtonIcon(class FObjectInitializer const &)" (??0UButtonIcon@@QEAA@AEBVFObjectInitializer@@@Z)
2>ButtonIcon.gen.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __cdecl UImage::UImage(class FObjectInitializer const &)" (__imp_??0UImage@@QEAA@AEBVFObjectInitializer@@@Z)
2>ButtonIcon.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl UImage::~UImage(void)" (__imp_??1UImage@@UEAA@XZ) referenced in function "public: virtual __cdecl UButtonIcon::~UButtonIcon(void)" (??1UButtonIcon@@UEAA@XZ)
2>ButtonIcon.gen.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl UImage::~UImage(void)" (__imp_??1UImage@@UEAA@XZ)
2>ButtonIcon.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UVisual::BeginDestroy(void)" (?BeginDestroy@UVisual@@UEAAXXZ)

and so on for other methods of `UImage`.

did you add UMG module dependency? add Slate and SlateCore

Aside of includes you need to add dependency modules. UE4 is divided in to modules and with both plugin and game project you create a all module that will be loaded to the engine, and yes that means you in reality always extending engine code, if your code crash entire engine crash.

Becuase of this structure UBT configures compilation in specific way and it needs to know which modules your module will communicate with, you can check which functions, clases etc. are in which module by looking on API refrence:

You can also deduce which module name is in by looking at the header file path, it directory before Public or Classes

Runtime/UMG/Public/Components/Image.h

You add dependency in to build script of you module (*.build.cs file), in there yhou will have this:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore"  });

just add modules to the list, remember to seperate them with commas and put names in quotations (simply keep C# validity, it actully more of a code then configuration file)

Aside of UMG module add also Slate and SlateCore, as UMG is just Slate (UE4 UI system) blueprint wrapper and it’s using Slate types, UMG would eventually force you to add those either way.

Without all this you will get linker errors like you getting right now, you get errors related to constructor as linker tries to link your class to it’s parent which is in UMG module.

I originally just had an include for Runtime/UMG/Public/Components/Image.h added slate.h and slatecore.h but this has made no difference to the outcome.

Oh and obviously include for CoreMinimal.h and the generated header too :slight_smile:

PERFECT! Many thanks!