Unknown type FCanvasTileItem in UE 4.5

Hello everyone,

Since there seem to have been some changes in how new projects are generated, I seem to be unable to figure out which of UE4.5’s header files FCanvasTileItem is defined in. In the custom class ARPGTestHUD, I have implemented code from the wiki’s FPS C++ tutorial in order to display a crosshair with C++ code (I didn’t want to use Blueprint because I want to save CPU cycles). RPGTestHUD.cpp has the two following methods:

ARPGTestHUD::ARPGTestHUD(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
    // Set the crosshair texture
    static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(TEXT("Texture2D'/Game/HUD/crosshair.crosshair'"));
    CrosshairTex = CrosshairTexObj.Object;
}

void ARPGTestHUD::DrawHUD()
{
    Super::DrawHUD();
    // Draw very simple crosshair
    // find center of the Canvas
    const FVector2D Center(Canvas->ClipX * 0.5f, Canvas->ClipY * 0.5f);
    // offset by half the texture's dimensions so that the center of the texture aligns with the center of the Canvas
    const FVector2D CrosshairDrawPosition( (Center.X - (CrosshairTex->GetSurfaceWidth() * 0.5)),
                                          (Center.Y - (CrosshairTex->GetSurfaceHeight() * 0.5f)) );
    // draw the crosshair
    
    FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTex->Resource, FLinearColor::White);

    TileItem.BlendMode = SE_BLEND_Translucent;
    Canvas->DrawItem( TileItem );
}

Unfortunately, it says "Variable has incomplete type ‘FCanvasTextItem’ despite having #include “Engine/Canvas.h” in the compiler directives at the top. I tried including Engine/CanvasRenderTarget2D.h, but that didn’t work either (in fact, doing so leads to Xcode complaining that CanvasRenderTarget.h has an incomplete type). Which file should I include to gain access to FCanvasTileItem?

Try #include “CanvasItem.h” this is where FCanvasTileItem is located, and this is what other files are including that use the class

It worked, thanks for the tip!