I have an replicated actor, with a StaticMesh component replicated too.
And i want to change its scale when it is attached.
I’m trying to use a RepNotify event to change the scale. (Because the scale replication using a RPC executing on server when it is attached to other actor does not work too).
In the Mesh Class (.h)
UPROPERTY(ReplicatedUsing=OnScaleChange)
FVector3d CurrentScale = FVector3d(1.0f,1.0f,1.0f);
UFUNCTION(Server, Unreliable)
void SetScale(const FVector3d &NewScale);
UFUNCTION()
void OnScaleChange();
In the Mesh Class (.cpp)
//----------------------------------------------------------------------------
void UAttachableStaticMeshComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> &OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION_NOTIFY(UAttachableStaticMeshComponent, CurrentScale, ELifetimeCondition::COND_None, ELifetimeRepNotifyCondition::REPNOTIFY_OnChanged);
}
//----------------------------------------------------------------------------
UAttachableStaticMeshComponent::UAttachableStaticMeshComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
PrimaryComponentTick.bCanEverTick = true;
bReplicatePhysicsToAutonomousProxy=true;
SetIsReplicatedByDefault(true);
}
//---------------------------------------------------------------------------
void UAttachableStaticMeshComponent::SetScale_Implementation(const FVector3d &NewScale)
{
CurrentScale = NewScale;
OnScaleChange();
}
//----------------------------------------------------------------------------
void UAttachableStaticMeshComponent::OnScaleChange()
{
SetWorldScale3D(CurrentScale);
message::Warning("UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->" +
CurrentScale.ToString() + " / " + FString::FromInt(GetOwner()->HasAuthority()));
}
//----------------------------------------------------------------------------
When it is not attached to an Actor RepNotify does work well (it is executed on server and client side).
LogTemp: Warning: AAttachableActor::Attach --> DONE ===>BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=0.250 Y=0.250 Z=0.250 / 1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=0.250 Y=0.250 Z=0.250 / 0
When it is attached to an Actor RepNotify event does NOT work well (it is executed on server side only).
LogTemp: Warning: AttachableActor::Detach --> DONE ===>BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=1.000 Y=1.000 Z=1.000 / 1
LogTemp: Warning: AAttachableActor::Attach --> DONE ===>BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=0.250 Y=0.250 Z=0.250 / 1
Do you know why this happen?
Why RPC and RepNotify does not work when the actor is attache to other actor?
Can i change the scale in some way?
Thak you so much!!
NOTE: All actors are replicated.