Redemp
(Redemp)
December 11, 2016, 8:24pm
1
Hi everyone,
I’m trying to do exactly the same done in the shootergame.
In myHUD.cpp I try to cast to my gamestate and it’s not working/
Can someone help me please ?
thanx.
here is my code:
void ATactical7DecHUD::DrawGameTimerAndPosition()
{
ATacticalGameState* const MyGameState = Cast<ATacticalGameState>(GetWorld()->GameState);
}
Kris
(Kris)
December 12, 2016, 12:24am
2
What is the actual error you are getting?
Or is it just a nullptr?
Try
void ATactical7DecHUD::DrawGameTimerAndPosition()
{
ATacticalGameState* const MyGameState = Cast<ATacticalGameState>(UGameplayStatics::GetGameState(GetWorld()));
}
Also, check to make sure that your GameMode subclass has
GameStateClass = ATacticalGameState::StaticClass();
in its constructor (or it’s otherwise correctly overrode). The cast will fail if the wrong gamestate was spawned, because you can’t cast it into something it’s not.
Redemp
(Redemp)
December 12, 2016, 9:26pm
4
So good, thank you very much it works very well.