Hi,
So I have a weird behaviour with Unreal’s Multiplayer, more specifically with actor replication.
I started from the third person template and what I wanted to do was spawn a blueprint class from my character’s BeginPlay method and attach it to the character, as the server is the only one that should spawn important objects I did it like this :
void AMyProjectCharacter::BeginPlay()
{
Super::BeginPlay();
if(Role == ROLE_Authority)
{
SpawnSphere();
}
}
void AMyProjectCharacter::SpawnSphere()
{
static ConstructorHelpers::FObjectFinder<UBlueprint> Bp(TEXT("/Game/Test"));
if(Bp.Object)
{
MyBlueprint = (UClass*)Bp.Object->GeneratedClass;
}
if(GetWorld())
{
shape = GetWorld()->SpawnActor<AShape>(MyBlueprint);
shape->SetOwner(GetOwner());
}
AttachSphere();
}
Now the AShape class as these lines in his constructor :
Mesh->SetIsReplicated(true);
Mesh->SetNetAddressable();
bReplicates = true;
Then as you see in the code above (the SpawnSphere Method) I call a function that is called AttachSphere and is like that :
UFUNCTION(Reliable, NetMulticast, WithValidation)
void AttachSphere();
void AMyProjectCharacter::AttachSphere_Implementation()
{
shape->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale, FName("ShapeC++"));
shape->SetActorRelativeLocation(FVector::ZeroVector);
}
Now this is what I get on the server :
Which is perfectly fine but on the client I have this :
The Spheres are absolutely not in the right place I’ve searched for long hours I found a post where people said that I should use AttachToComponent on the server and on the clients which I tried to do with the NetMulticast function but I can’t get it working.
If any information is missing please tell me,
Thank you,