So I am still learning C++ but been using it for quite a while. But I have a function which is not working properly (separate question posted here: Calling Client RPC in order to assign a Team value to clients. How to check the Role properly? - Development Discussion / Multiplayer & Networking - Unreal Engine Forums).
I am starting to think the problem MIGHT be about how I cast from the APawn* to APlayerMallet* (which is actually extending ACharacter not APawn).
APlayerMallet* mallet=(APlayerMallet*)gamestate->PlayerArray[i]->GetPawn();
The code compiles and it does find the function in APlayerMallet if I change the IF statement to force it to call the function in APlayerMallet.
I suppose here I am just looking for confirmation that it is ok to do such a cast.
(APlayerMallet*)
) basically tells the compiler: "I know what I'm doing don't do any checks. Whatever is at GetPawn address, interpret it as a APlayerMallet." Combined with "So I am still learning C++", I think you should try a static cast instead. The compiler will make sure that the type can be correctly cast. DoesACharacter
extendAPawn
? \$\endgroup\$