We are writing
GameModeRef=Cast(UGameplayStatics::GetGameMode(GetWorld()));
Can’t we just Write:
GameModeRef=(ATankGameModeBase* )(UGameplayStatics::GetGameMode(GetWorld()));
as usual c++ Syntax;
Will it not Work??
We are writing
GameModeRef=Cast(UGameplayStatics::GetGameMode(GetWorld()));
Can’t we just Write:
GameModeRef=(ATankGameModeBase* )(UGameplayStatics::GetGameMode(GetWorld()));
as usual c++ Syntax;
Will it not Work??
To be really pedantic that’s technically that’s C syntax. C++ has the named casts (static_cast
, dynamic_cast
, etc.)
It will “work” but it’s not type safe. If the game mode isn’t an ATankGameModeBase
then you will get undefined behaviour. Whereas with Cast<>
it will be set to nullptr
which you can check against.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.