Description

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.

Steps to Reproduce

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.

 

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-115945 in the post.

9
Login to Vote

Backlogged
ComponentUE - Rendering - RHI
Affects Versions4.264.275.0
CreatedMay 18, 2021
UpdatedApr 19, 2022
Pull Requests
9065 - HSeo