Network client calls BeginPlay twice on GameState

I noticed that BeginPlay function on my game state object is called twice. My game state wasn’t designed to handle this, so it ended up spawning two copies of various actors. Is that a bug? If not, are all actors require to handle multiple calls of BeginPlay?

I can reproduce this with Unreal 4.7.1 as follows:

  1. Create BasicCode C++ project.

  2. Add custom game state class to project and override BeginPlay as follows:

    #pragma once

    #include “GameFramework/GameState.h”
    #include “MyGameState.generated.h”

    class BASICCODE_API AMyGameState : public AGameState

     virtual void BeginPlay() override
     	UE_LOG(LogTemp, Warning, TEXT("BeginPlay of %s (0x%016x)"), *this->GetName(), this);


  3. Create custom game mode blueprint that uses custom game state class, configure project to use custom game mode.

  4. Pulling down play dropdown, Advanced Settings, set:

    Number of Players: 2
    Use Single Process: Unchecked
    Editor Multiplayer Mode: Play as Client

  5. Click Play button to run.

RESULT: Debug output contains two BeginPlay lines.

[2015.03.27-21.30.09:030][341]LogTemp:Warning: BeginPlay of MyGameState_8 (0x00000000de80f800)

[2015.03.27-21.30.16:394][341]LogTemp:Warning: BeginPlay of MyGameState_8 (0x00000000de80f800)

EXPECTED: Debug output only shows a single occurrence of BeginPlay.

Setting breakpoints, I see that first call comes from:

>	UE4Editor-BasicCode.dll!AMyGameState::BeginPlay() Line 18	C++
 	UE4Editor-Engine.dll!AWorldSettings::NotifyBeginPlay() Line 119	C++
 	UE4Editor-Engine.dll!AGameState::OnRep_MatchState() Line 228	C++
 	UE4Editor-CoreUObject.dll!UFunction::Invoke(UObject * Obj, FFrame & Stack, void * const Result) Line 3684	C++
 	UE4Editor-CoreUObject.dll!UObject::ProcessEvent(UFunction * Function, void * Parms) Line 920	C++
 	UE4Editor-Engine.dll!AActor::ProcessEvent(UFunction * Function, void * Parameters) Line 529	C++
 	UE4Editor-Engine.dll!FRepLayout::CallRepNotifies(FRepState * RepState, UObject * Object) Line 1529	C++
 	UE4Editor-Engine.dll!FObjectReplicator::PostReceivedBunch() Line 749	C++
 	UE4Editor-Engine.dll!UActorChannel::ProcessBunch(FInBunch & Bunch) Line 1901	C++

second call comes from:

>	UE4Editor-BasicCode.dll!AMyGameState::BeginPlay() Line 18	C++
 	UE4Editor-Engine.dll!AActor::PostNetInit() Line 2434	C++
 	UE4Editor-Engine.dll!UActorChannel::ProcessBunch(FInBunch & Bunch) Line 1916	C++

Adding an Unreal project that can be used to reproduce. Run from Visual Studio with a breakpoint on AMyGameState::BeginPlay. Play as client to see two calls to BeginPlay.

Isn’t it just calling BeginPlay on Server (which is replicated to client) and on client itself? Seems normal to me.

Just make sure that Role == ROLE_Authority, so that only server calls it.

I don’t think so. I am running in mode Play as Client with Use Single Process unchecked. So my understanding is that I am seeing BeginPlay calls on client. Also note from debug output that game state is at same memory address each time, suggesting that it is same object having BeginPlay called twice. Role is ROLE_SimulatedProxy in both cases.

Hi Forrest,

Thanks to information you provided, I was easily able to see results that you described, and was able to reproduce it in my own test project as well. I have submitted a report of what I observed to have this investigated further (UE-13429).

Thanks !

Has this issue been resolved earlier? Because I’m having very same problem right now and it’s making it impossible to work

I don’t know if this is fixed in latest Unreal engine, but you can work around problem by setting a bool in your game state object when BeginPlay is called. In second call to BeginPlay, skip out if bool is already set.

Hi Serellyn,

There’s been no update on bug entered. We’ll post here when we see any change.

I had an issue where all of Begin Plays on my actors didn’t work. I turned out it was because of GameState class i made wasnt compatible with GameModeBase.

GameState is only compatible with GameMode and GameStateBase with GameModeBase