Hey people, something very odd is happening while updating my cross-hair textures.
The C++ code is as follows:
ATest_FPSHUD::ATest_FPSHUD()
{
// Set the crosshair texture
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(TEXT("/Game/FirstPerson/Textures/Green_Crosshair"));
CrosshairTex = CrosshairTexObj.Object;
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexEnemyObj(TEXT("/Game/FirstPerson/Textures/FirstPersonCrosshair"));
CrosshairTexEnemy = CrosshairTexEnemyObj.Object;
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexDisabledObj(TEXT("/Game/FirstPerson/Textures/Green_Crosshair_Disabled"));
CrosshairTexDisabled = CrosshairTexDisabledObj.Object;
DrawEnemyCrosshair = false;
/*
* 0 = Green/Normal
* 1 = Red/Enemy
* 2 = Disabled/Over NPC
*/
CrosshairType = 0;
}
void ATest_FPSHUD::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 textures dimensions so that the center of the texture aligns with the center of the Canvas
const FVector2D CrosshairDrawPosition( (Center.X),
(Center.Y));
// draw the crosshair
FCanvasTileItem TileItem(CrosshairDrawPosition, CrosshairTexEnemy->Resource, FLinearColor::White);
TileItem.BlendMode = SE_BLEND_Translucent;
switch (CrosshairType)
{
case 0 :
TileItem.Texture = CrosshairTex->Resource;
break;
case 1:
TileItem.Texture = CrosshairTexEnemy->Resource;
break;
case 2:
TileItem.Texture = CrosshairTexDisabled->Resource;
break;
default:
break;
}
Canvas->DrawItem( TileItem );
}
This works fine in a new level I made, but in my original level, it seems the crosshair texture is not updated correctly (and even always setting my code to pick case 1, it still doesn’t update)
Working level:
Non-working level:
The blueprint for this is very simple as well:
Any help would be appreciated, thanks!