**[SOLVED]
**
I’m reaching to the community for help after hours of failures.
Quick summary of what I wanted to achieve:
- Client wants to prone so it calls a server function.
- Server sets bIsProned to true and replicates it clients, additionaly it sets additional parameters localy ( presented in code below )
- Clients call OnRep_bIsProned function locally to adjust the parameters aswell
- Both Server and Clients see the same thing:
*main collision capsule is resized to a ball size
*mesh sits right in the center of the secondary collision capsule
*mesh also is visible above the ground
What I got:
1.-3. is the same.
4.a ( when local server wants to prone )
4.b ( when client 1 wants to prone )
I also attach some code for further investigation of the problem
UPROPERTY(BlueprintReadOnly, ReplicatedUsing = OnRep_IsProned, Category = Character)
bool bIsProned = false;
UFUNCTION()
void OnRep_IsProned();
bool AToW_PlayerCharacter::CanProne()
{
TArray< AActor * > OverlappingActors;
ProneCapsuleCollision->GetOverlappingActors(OverlappingActors);
return !bIsProned && GetRootComponent() && !GetRootComponent()->IsSimulatingPhysics() && (OverlappingActors.Num() <= 1);
}
bool AToW_PlayerCharacter::CanUnProne()
{
TArray< AActor * > OverlappingActors;
GetCapsuleComponent()->GetOverlappingActors(OverlappingActors);
return bIsProned && GetRootComponent() && !GetRootComponent()->IsSimulatingPhysics() && (OverlappingActors.Num() <= 1);
}
void AToW_PlayerCharacter::ProneToggle()
{
if (!bIsProned && CanProne() && bCanChangeState)
{
bCanChangeState = false;
GetCharacterMovement()->MaxWalkSpeed = 0.0f;
bIsProned = true;
UpdateProneCollisionCapsule();
bIsStanding = false;
CurrentMovementState = PRONING;
if (!bIsCrouching) RefreshMovementSpeedDelayed(fStandToProneTime);
else
{
RefreshMovementSpeedDelayed(fCrouchToProneTime);
bIsCrouching = false;
}
}
else if (bIsProned && CanUnProne() && bCanChangeState)
{
bCanChangeState = false;
GetCharacterMovement()->MaxWalkSpeed = 0.0f;
bIsProned = false;
UpdateProneCollisionCapsule();
bIsStanding = true;
CurrentMovementState = JOGGING;
RefreshMovementSpeedDelayed(fStandToProneTime);
}
if (Role < ROLE_Authority)
{
ServerProne();
}
}
void AToW_PlayerCharacter::ServerProne_Implementation()
{
ProneToggle();
}
bool AToW_PlayerCharacter::ServerProne_Validate()
{
return true;
}
void AToW_PlayerCharacter::OnRep_IsProned()
{
if (Role < ROLE_Authority)
{
UpdateProneCollisionCapsule();
}
}
void AToW_PlayerCharacter::UpdateProneCollisionCapsule()
{
if (bIsProned)
{
ProneCapsuleCollision->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
GetCapsuleComponent()->SetCapsuleHalfHeight(10.0f);
ProneCapsuleCollision->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
GetMesh()->AddRelativeLocation(FVector(0.0f, 0.0f, 60.0f));
SetActorLocation(GetActorLocation() + FVector(0.0f, 0.0f, -25.0f));
}
else if (!bIsProned)
{
ProneCapsuleCollision->SetCollisionEnabled(ECollisionEnabled::NoCollision);
GetCapsuleComponent()->SetCapsuleHalfHeight(88.0f);
ProneCapsuleCollision->SetRelativeLocation(FVector(0.0f, 0.0f, -60.0f));
GetMesh()->AddRelativeLocation(FVector(0.0f, 0.0f, -60.0f));
SetActorLocation(GetActorLocation() + FVector(0.0f, 0.0f, 25.0f));
}
}
void AToW_PlayerCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, RepRootMotion, COND_SimulatedOnly);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, ReplicatedBasedMovement, COND_SimulatedOnly);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, ReplicatedMovementMode, COND_SimulatedOnly);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, bIsCrouching, COND_SkipOwner);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, bIsProned, COND_SkipOwner);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, bIsStanding, COND_SkipOwner);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, bIsAiming, COND_SkipOwner);
DOREPLIFETIME_CONDITION(AToW_PlayerCharacter, bCanChangeState, COND_SkipOwner);
DOREPLIFETIME(AToW_PlayerCharacter, fAimingPitch);
DOREPLIFETIME(AToW_PlayerCharacter, fAimingYaw);
}
Hope to hear a response soon!