When compiled, linker errors appear
1>LensDistortionBlueprintLibrary.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UTexture2D::Serialize(class FArchive &)" (?Serialize@UTexture2D@@UEAAXAEAVFArchive@@@Z)
1>Module.LensDistortion.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl UTexture2D::Serialize(class FArchive &)" (?Serialize@UTexture2D@@UEAAXAEAVFArchive@@@Z)
It looks like this is purely an access error and can be fixed by switching all the virtual functions to ENGINE_API or "ENGINE_API virtual" and/or correcting virtual/override declarations in other inherited classes such as UVirtualTexture2D too.
In a new or existing plugin, add a new class to a header file (for testing I used LensDistortionBlueprintLibrary.h), e.g.
UCLASS(MinimalAPI) class UTexture2DExtended : public UTexture2D { GENERATED_UCLASS_BODY() public: float test; };
Add #include "Engine/Texture2D.h"
In the associated build.cs, ensure that "Engine" is in the PublicDependencyModuleNames. You may also need something like "../../../../Source/Runtime/Engine/" in PrivateIncludePaths (these already exist in LensDistortion.Build.cs)
Add the following to an associate cpp file:
UTexture2DExtended::UTexture2DExtended(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) {}
If you change the Texture2D to UTexture or UTextureRenderTarget2D, the compilation works fine.
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-115945 in the post.
12 |
Component | UE - Rendering - RHI |
---|---|
Affects Versions | 4.26, 4.27, 5.0 |
Created | May 18, 2021 |
---|---|
Updated | Apr 19, 2022 |
9065 |