UE 4.5.1: Code project featuring UTextureRenderTarget2D reference won't compile despite #include "Engine/TextureRenderTarget2D.h" in .cpp file

I have a HUD subclass called ARPGTestHUD, and it features a reticule in the center of the screen alongside what is supposed to be a minimap (it’s a render texture that shows the view from a camera positioned above the player character’s head, facing downwards).

RPGTestHUD.h features a forward class declaration:

class UTextureRenderTarget2D;


    /** Minimap asset pointer */
    UTextureRenderTarget2D* MiniMapTex;


And it includes Engine/TextureRenderTarget2D.h in RPGTestHUD.cpp.

#include "Engine/Canvas.h"
#include "Engine/TextureRenderTarget2D.h"
#include "CanvasItem.h"
#include "RPGTestHUD.h"

ARPGTestHUD::ARPGTestHUD(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
    // Set Minimap texture
    static ConstructorHelpers::FObjectFinder<UTextureRenderTarget2D> MiniMapTexObj(TEXT("Texture2D'/Game/HUD/MapTarget.MapTarget'"));
    MiniMapTex = MiniMapTexObj.Object;

void ARPGTestHUD::DrawHUD()
    // Draw minimap
    FCanvasTileItem MiniMapTileItem(MiniMapDrawPosition, MiniMapTex->Resource, FLinearColor::White);
    MiniMapTileItem.BlendMode = SE_BLEND_Translucent;
    MiniMapTileItem.Size = FVector2D(256, 256);
    Canvas->DrawItem( MiniMapTileItem );

Unfortunately, it fails to compile in Xcode on the following line:

FCanvasTileItem MiniMapTileItem(MiniMapDrawPosition, MiniMapTex->Resource, FLinearColor::White);

The error is “no member named 'Resource in ‘UTextureRenderTarget2D’”. This is possibly due to Engine/TextureRenderTarget2D.h claiming that UTextureRenderTarget (the superclass of UTextureRenderTarget2D) is an unknown class name. It’s a really bizarre error because my project is not a GitHub project. Am I missing any #includes in RPGTestHUD.cpp, or is there some other problem?

Hi Alonzo,

I just wanted to clarify which version of the Engine you are using. Is it 4.5.1?

Yes, I am using version 4.5.1.

Hi Alonzo,

I was able to reproduce the issue that you have described, and have entered a ticket to have this investigated and possibly improved (UE-5050).

In the meantime, you can get around this error by adding the line #include "Engine/TextureRenderTarget.h" to the file TextureRenderTarget2D.h. Unfortunately this will most likely not work in the binary version of the Engine (I keep receiving an internal compiler error from Visual Studio, and I expect you will see something similar in XCode).

Yes, there is a series of internal errors in Engine/TextureRenderTarget2D.h, starting with a Shell Script Invocation Error with the subtext “Unknown class ‘TextureRenderTarget’; did you mean ‘TextureRenderTarget2D’?”. Looking in TextureRender2D.h in the engine source, the line “#include “TextureRenderTarget.h”” was found to be missing as you have said. Editing the engine code fixed the bug. Thanks!

ADDENDUM: Even if a code project has been created using the editor, engine source bugs can still be fixed by going to your default common source code that is installed whenever you install a new version of the engine (on OS X, it’s in /Users/Shared/UnrealEngine/4.5/Engine/Source/)