Does BeginPlay() get called on Client?

I have an Actor that is placed in the Map , with a Replicated bool bDisabled. Whenever it changes mid game, a RepNotify calls an Enabled/Disabled function which works perfectly fine.

However, during BeginPlay() the Actor checks if it’s disabled, and if it is it hides the Mesh and disables the collision. However this never gets called on the Client so the it’s never disabled, and the RepNotify doesn’t get called during the initialization of the Client when they join, so it only has the variable updated but the function isn’t called initially.

My logs see to indicate BeginPlay doesn’t get called locally for clients, but just wanted to see if I was doing something wrong before I rewrite my logic.

.h

// Disables collision/rendering, must be reenabled by calling EnableTarget() in Blueprints
UPROPERTY(ReplicatedUsing=ToggleEnabled,EditAnywhere,BlueprintReadWrite, Category = "Target")
bool bDisabled;

.cpp

void AROTTrainingTarget::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME(AROTTrainingTarget, bDisabled);
}

void AROTTrainingTarget::BeginPlay()
{
	Super::BeginPlay();
	
	if (HasAuthority())
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Blue, TEXT("Server"));
	else
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Green, TEXT("Client"));
	//Begin activation
	if (bDisabled)
	{
		DisableTarget(); 
		return;
	}

	EnableTarget();

}

void AROTTrainingTarget::ToggleEnabled()
{
	GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Cyan, TEXT("ToggleEnabled!"));

	if (!bDisabled)
		EnableTarget();
	else
		DisableTarget();
}

void AROTTrainingTarget::EnableTarget()
{
	UE_LOG(Log, All, TEXT("%s - EnableTarget()"), *GetName());
	
	if (HasAuthority())
	{
		switch (ActivationType)
		{
		case EActivationType::ENUM_Blueprint:
			PopDown();
			break;
		case  EActivationType::ENUM_Radial:
			PopDown();
			break;
		case EActivationType::ENUM_Active:
			Popup();
			break;
		}
	}

	Mesh->SetHiddenInGame(false);
	bDisabled = false;
	Mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
}


void AROTTrainingTarget::DisableTarget()
{
	Mesh->SetHiddenInGame(true);
	bDisabled = true;	
	Mesh->SetCollisionEnabled(ECollisionEnabled::NoCollision);
}

BeginPlay is called by Level so it doesn’t matter if you are server or client, it will always be called.

For the RepNotify to being called, your variable need to change, for example, if default is true, when you start it will never call RepNotify until variable is false.

You code seem fine to me, maybe you can try to use GetNetMode to check for client or server.

Still nothing. My BeginPlay() function on the client does not seem to be called, only the Server gets it ran.

In UE3/UDK I use to have to declare a function as “Simulated” in order for it to be allowed to be ran on a client. Is this still true in UE4? As there appears to be no indication of it

Still haven’t really found an answer on this, but I don’t seem to get any logs for the clients for BeginPlay(), but PostInitializeComponents() works for clients when they load the game it seems. Seems like there is no reason why I can’t use this function, as it’s before the game starts.

the same issue with 4.11, only server call beginplay, even break point not breaking…

I never could get this fixed, only thing I had to do was recreate the project and start from scratch. No clue what caused it.

Once I made a new project it was working fine, BeginPlay() called all the time.