Why RPC/RepNotify does not work when the actor is attached to other actor?

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.


It could be a matter of ownership. The child actor may not be owned by the controller trying to enforce the change in scale. Try to trigger the scale change from the parent actor or change the child actors ownership.

1 Like

Hi @3dRaven

Thanks for your answer!!

i just test the ownership. I think it is not the problem.
Anyway i going to explain you what i did (just in case).


-When it is attached i set the cube owner like this (I’m using a actor componet to attach).

AttachableActor->SetOwner(GerOwner());

-When it is detached i set the cube owner to NULL.

AttachableActor->SetOwner(nullptr);

I’m checking the ownership from the StaticMesh component like this:

	if (GetOwner())
	{
		if (GetOwner()->GetOwner())
		{
			message::Warning("UAttachableStaticMeshComponent::OnScaleChange -> 
                        OWNER -->" + GetOwner()->GetOwner()->GetName() );		
		}		
	}

So… This is happening:
-First the cube is placed in world (it has not owner)
-Then it overloap with an non-character actor (it has not controller)
-RepNotify does works (it is executed in server and client side).
-The cube is attached to this actor and its scale change well in the server and client.
-The new cube owner is BP_BlueBase_C_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 / BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> OWNER -->BP_BlueBase_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=0.250 Y=0.250 Z=0.250 / 0 / BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> OWNER -->BP_BlueBase_C_1

-Then the character go to the BlueBase and when is overlapping detach the cube.
-Now the cube has not owner.
-The scale change too. But it is execute on server side only. (I don’t know why). But this change is replicated (client and server can see a big cube).

LogTemp: Warning: AttachableActor::Detach --> DONE  ===> BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=1.000 Y=1.000 Z=1.000 / 1 / BP_BlueCube_C_1

-Now the character attach the cube.
-The new cube owner is the character.
-The cube scale change but this time it is not replicated (only server can see a little cube)
-The RepNotify is executed in server side only
-The cube scale is not replicated

LogTemp: Warning: AAttachableActor::Attach --> DONE ===> BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> EXEC -->X=0.250 Y=0.250 Z=0.250 / 1 / BP_BlueCube_C_1
LogTemp: Warning: UAttachableStaticMeshComponent::OnScaleChange -> OWNER -->BP_RedTeamCharacter_C_0

So… in this point client see a big cube and the server see a little cube.
-RepNotify does not work after the first step.
-Scale replication does not work after the second step.


What do you think about it?
Thank you!!

To be clear is the element you wish to change scale is a component or another actor attached as a child actor component?

The title would suggest a child actor component yet your element is named UAttachableStaticMeshComponent suggesting it normal sub component.

-It is an actor (it is a cube) → i call it AttachableActor
-The cube has a static mesh component–> i call it UAttachableStaticMeshComponent

i attaching it like this:

	const FAttachmentTransformRules AttachmentRules = FAttachmentTransformRules
	(
			EAttachmentRule::SnapToTarget,
			EAttachmentRule::SnapToTarget,
			EAttachmentRule::SnapToTarget,
			true
	);

	SetAttachedConfig(); //-->handle conllision response
	
	if (!AttachToComponent(Parent, AttachmentRules, SocketName)) return;

This is the AttachableActor code (others actor can use it to handle the attachament)

I’ sorry… i acept you answer by accident…
I want tell you i going to send you the code by private message

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.