Yes, did you compile the engine in Debug Editor? The fact that you are returning right away leads me to believe the character’s player controller reference has already been removed. I don’t know where ::Die() is called in your execution chain so I can’t really judge. Try this function instead:
void AMyCharacter::Die(AActor* killer)
if (Role < ROLE_Authority || !bCanDie || !killer) return;
APAGameMode* gameMode = Cast<APAGameMode>(GetWorld()->GetAuthGameMode());
AController* myController = GetController();
if (gameMode != nullptr && myController != nullptr)
else if (myController != nullptr)
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("CAN'T GET GAME MODE")));
if (GEngine) GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("PLAYER CONTROLLER IS MISSING")));
I think what Manoel was trying to say is you need to trace in to RestartPlayer to see why it’s not restarting. There is a lot that could be going wrong here. Are you sure restart player is being called on the server? Are you sure all of the needed vars are valid? On and on. Without tracing in to your RestartPlayer call it’s hard to just judge from a forum post what might be going wrong. As to how to enable Debug Editor, it’s a solution configuration. Just change it from Development Editor to Debug Editor.
Well, for starters, if this is a multiplayer game and your Die() function is called from TakeDamage() and you are connected to a dedicated server then the call to AddOnScreenDebugMessage() won’t work since it will be running on the server and the server doesn’t have a screen. I’d start by suggesting you make them logs not onscreen debug. Something like:
But you need to learn how to actually debug the code. You’ll save yourself a lot of time. Change the solution configuration to Debug Editor, recompile then re-run the game. Set a breakpoint on the call to RestartPlayer in your Die() function. Trace in and see why it’s not restarting. I can keep making minor helpful suggestions but really this isn’t something I can debug in the forums for you.
Are you using the github version? You can’t compile changes made to the engine source code in launcher builds. Anyway, you should override that function in your own GameMode class instead of modifying the engine implementation because it works regardless of launcher/github and is much easier to maintain.
These functions are not returning errors or anything.
The very last step of these functions is: **K2_OnRestartPlayer **which is defined as:
/** Implementable event called at the end of RestartPlayer */
UFUNCTION(BlueprintImplementableEvent, Category=Game, meta = (DisplayName = "OnRestartPlayer", ScriptName = "OnRestartPlayer"))
void K2_OnRestartPlayer(AController* NewPlayer);