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);
}