Hey, i’m trying to get access to my HUD from my FPS character.
Currently i’m trying this out
APlayerController* MyPC = Cast<APlayerController>(Controller);
MyHUD = Cast<AProject_RewindHUD>(MyPC->GetHUD());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, "Error!");
But this does not work for me as i’m always getting the error. From what i read this should work. Anyone have any idea why it is not working for me? I currently have no self made player controller class, is one required to get the HUD?
Bumping this up a bit, I’m having the same issue, but with casting AAIController to AController:
pawnController = Cast(OwnerComp.GetAIOwner());
This is giving me this error message:
Error 2 error C2664: ‘AController *TCastImpl<From,To,UObjectToUObject>::DoCast(UObject *)’ : cannot convert argument 1 from ‘AAIController *’ to ‘UObject *’ C:\Program Files\Epic Games\4.7\Engine\Source\Runtime\CoreUObject\Public\Templates\Casts.h 135 1 LostEchoes
Have you declared the MyHUD variable? E.g. have you tried the following:
AHUD* MyHUD = Cast(MyPC->GetHUD());
You could also check if your PC or HUD is valid:
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, MyPC->GetName());
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Green, MyHUD->GetName());
What is your error message?
when do you call that method? Can you please check if the Controller isn’t NULL at that point before, so we know it’s a matter of the cast. (as it might as well just be NULL already before and you try to cast → NULL again)
Maybe you need to call the method after the pawn is possessed by a controller ( I guess you call it really early, like in the constructor?)