I’m having an issue understanding how to dynamically change the crosshair in the firstperson hud class. What I want to do is have it dynamically change depending on what object is being targeted, from a regular crosshair to a hand icon for interactable items. To test this theory, currently I’m trying to have the crosshair change if I can get a reference to the player character:
ABasicFPSHUD::ABasicFPSHUD()
{
ABasicFPSCharacter* Character = Cast<ABasicFPSCharacter>(UGameplayStatics::GetPlayerCharacter(this, 0));
FString crosshairPath;
TCHAR* something;
if (Character != nullptr) {
UE_LOG(LogTemp, Warning, TEXT(“Charcter not null”))
something = TEXT("/Game/FirstPerson/Textures/hand");
UE_LOG(LogTemp, Warning, TEXT(“the text is %s”), something)
}
else {
something = TEXT("/Game/FirstPerson/Textures/FirstPersonCrosshair");
}
// Set the crosshair texture
static ConstructorHelpers::FObjectFinder<UTexture2D> CrosshairTexObj(something);
CrosshairTex = CrosshairTexObj.Object;
}
it is printing the “character not null” and It’s printing the correct path, but it still falls back on the else statement, and when I start the game I still get the else statement crosshair. What am I doing wrong?