AHUD or APlayerController -> BeginPlay is not called, is it normal?

Function BeginPlay is not called when i start the game.

MyGameMode->StartPlay // called
MyHUD->BeginPlay // not called
MyPlayerController->BeginPlay // not called

Why GameMode has its own StartPlay, but HUD and PlayerController has not?

All examples i’ve seen are using BeginPlay functions, but they dont work. At least in UE4.8.1.
Any ideas?

BeginPlay deprecated? or BUG?

Which function should i use for initializing HUD and PlayerController?

FIXED:
Was my fault:
AMyGameMode::StartPlay()
{
Super::StartPlay(); // added + fixed.

}

GameMode::StartPlay has a different purpose than BeginPlay. BeginPlay is called when the actor is created. GameMode::StartPlay is called when the match starts, which can be delayed if you specify custom conditions before starting the match, like waiting for players.

As for why your BeginPlay isn’t called, make sure in all your related parent and subclasses that if you have overriden BeginPlay, you also call the parent function. So in your C++ classes make sure you call Super::BeginPlay and in your blueprint classes with a BeginPlay node also add a call to the parent implementation (right click on the node). Hope that helps. :slight_smile:

oh my god.
yes, i completely forgot Super::BeginPlay.
and am also completely wonder why when i added Super::BeginPlay everything become working,
because i dont understand how my Log functions inside MyHUD::BeginPlay related to Super::BeginPlay call. C++ bug or new feature? From all physics laws MyHUD::BeginPlay should be called without Super::BeginPlay and thats it, but instead - entire BeginPlay, including MyHUD::BeginPlay, is not called. I dont understand this new C++ physics laws.

StartPlay() in GameMode calls BeginPlay() on all actors in your level. This means that BeginPlay() is actually called when the Actor is created but ONLY if the gamemode has called StartPlay(). However, this is not true for Clients in Multiplayer, who will call BeginPlay() regardless. A somewhat irritating quirk of Multiplayer, but I believe necessary for Replication to work properly.

You have to call Super::BeginPlay() because otherwise you’re not doing whatever AActor does when it calls BeginPlay(), which you need to. I believe that’s where some actors are registered for Garbage Collection and where they start ticking as well. It differs per-actor. In fact, you should call Super on any overridden function unless you really don’t want to, or expect difficult-to-trace bugs to appear!

That explains everything, because my StartPlay did not have Super::StartPlay also, but now it does.
And if i remove Super::StartPlay, then everything is not working again, even if i have all Super::BeginPlay.

So all C++ laws on its places.

thx.

PS: did not programm for a while, completely forgot about Super calls.

Haha yeah, I’ve had it a few times and the problem was just me forgetting to call Super :wink:

I’m speaking from experience as well! :smiley: