Problem replicating a scene component.

I’m trying to replicate the position of a scene component.
But i don’t have the same transform values on the server and client side.
Give me a hand please. What am I doing wrong?

The actor is replicated.

The component is replicated

Component

This is the component tree of the actor

Tree

This is how I am printing the values

This is a log capture

And this is a video

If you need more information just ask me

Thank you so much!!


UPDATE


I was tracing the code. i think the problem start when the weapon is attached.
This code is exectuted on server.


const FAttachmentTransformRules AttachmentRules =	FAttachmentTransformRules
	(
			EAttachmentRule::SnapToTarget,
			EAttachmentRule::SnapToTarget,
			EAttachmentRule::KeepWorld,
			true
	);
	
	AttachToComponent(Parent, AttachmentRules, SocketName);

However after this the transform is not igual in both sides.
¿Any idea?

It looks like you are controlling the movement from the client’s input, so it will only update on the client and not the server. If you do it from the perspective of the server, does it update correctly?

1 Like

Let me try it. Thank you so much!!

Ohh, i sorry now understand it.
Yes, the server does it update correctly.
the server has not problem

Is the weapon being attached to the player pawn?

Yes.
-First the weapon is spawned in the world
-Then the player pick up the weapon and attach it
-And the probem start here (Only for the client)

if you want i’ll upload other video to show you all this.

like this:

No need, the issue isn’t the weapon, it is actually the player pawn. If the movement is replicated, the location will update when walking around. In the pawn settings, are you using controller rotation yaw or pitch? Generally, you would just use yaw, then manually set the control rotation pitch to feed into an aim offset (for animation BP). This will make it so the entire pawn doesn’t rotate its pitch, just the mesh. For testing purposes, if you enable use controller pitch as well (assuming yaw is already enabled), this should correct the issue.

Edit: you should use a listen server with 1 server player and 1 client player. Then using the client, walk in view of the server player and move/look around. This should show you what is being replicated.

1 Like

I’m using this cofiguration:

I have a replicated control rotation to get move the spine bone of the pawn.

And this configuration in the character class.

control rotarion2

The case is this configuration work for me for months.
The weapon worked too.
I change the character a few days ago and the problems started.

I going to show you other video… replication work well (I think)

Look this:

Can you show what the player component hierarchy looks like? And what component are you attaching the weapon to?

Yes, of course… i going to do it now.

I just to edit two videos more becouse i want to show you this.
This is very very rare.

When the server no see the client, the client can not shoot (the tranform is not replicated well)…

When the server see the client, the client can shoot well (the weapon works)

Very confused…

I goint to get this…

wait a moment please.

The SceneComponents:

I attaching the weapon to a socket in the skeleton.

I just realize… i posted a wrong video in my las post (The second video) i fixed it…
What do you think about it?

When attaching, try setting the location to snap to target, but for rotation make it keep relative. See if it helps.

like this?

const FTransform WeaponSocket = AttachableStaticMesh->GetSocketTransform(FComponentSocketName::RightHand, RTS_Component);
AttachableStaticMesh->SetRelativeTransform(WeaponSocket.Inverse());

this no help… i already was using it

or do you mean like this?

	const FAttachmentTransformRules AttachmentRules =	FAttachmentTransformRules
	(
			EAttachmentRule::SnapToTarget,
			EAttachmentRule::KeepRelative,
			EAttachmentRule::KeepWorld,
			true
	);	
	AttachToComponent(Parent, AttachmentRules, SocketName);

it does not work too.

i try the character control rotation too. More or less works… but the projectile is not spawned exactly in the weapon cannon.

void AWeaponAttachable::SpawnProjectile_Implementation(APawn* TheInstigator, TSubclassOf<AActor> Projectile)
{
	if (!IsValid(SpawnLocation))
	{
		message::Error("AWeaponAttachable::SpawnProjectile -> SpawnLocation is NULL");
		return;		
	}

	const FVector Location = SpawnLocation->GetComponentLocation( );
	//const FRotator Rotation = SpawnLocation->GetComponentRotation( );
	const FVector  ForwardVector = SpawnLocation->GetForwardVector();
	const FRotator Rotation = TheInstigator->GetControlRotation();
	
	
	const FVector VtSpawnLocation = FVector
	(
		Location.X + ForwardVector.X * 1.0f, // 50.0f,
		Location.Y + ForwardVector.Y *1.0f, // 50.0f,
		Location.Z + ForwardVector.Z * 0.0f
	);	
	
	UWorld* World = GetWorld();
	if (!IsValid(World))
	{
		message::Error("AWeaponAttachable::SpawnProjectile -> World is NULL");
		return;		
	}	

	FActorSpawnParameters SpawnParameters = FActorSpawnParameters();
	SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
	SpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
	SpawnParameters.Owner = this;
	SpawnParameters.Instigator = TheInstigator;
	
	World->SpawnActor(Projectile, &VtSpawnLocation, &Rotation, SpawnParameters);
}

You have the GripPoint socket, but where do you use it? I only see RightHand

1 Like

Good question!!

Basicly it is the variable “socketName” in here…

i’m using poliformismis and virtual functions to handle several attachable objects.

virtual FName GetParentSocketName() override;

So the weapons objects use this:


FName AWeaponAttachable::GetParentSocketName()
{
	return FComponentSocketName::Weapon;
}

i have defined the socket names in a struct.
inline static const FName Weapon = "GripPoint";

Basicly if the pawn is overlapping with a attachable object and it is a weapon then is attached in the hand…

1 Like

You got a point… this skeleton has not “FComponentSocketName::RightHand” Socket… i goint to add it to check if it help.

1 Like

Ok, it was not help…
Did you see the video where the cannon position works when the server can see the client?
So rare…
What do you think about it?