"Hello everyone,
I’ve been studying Replication to add multiplayer functionality to a simple action game I’ve created. However, I’m encountering a ‘No owning connection for actor’ warning, but the function being Executed. (This could be because I’m running it in PIE (Play-In-Editor) mode)
However, the Replicate function executed in BeginPlay does not take effect. For example, if you call SetRoleMode() in the BeginPlay function, only the server works, and the client does not respond. I’ve searched online and suggestions include checking the Owner or using Possess in PostLogin() using GameMode, but the issue remains unresolved. Both Player and Enemy use the same component.
Anyway, the important thing is that a warning appears every time the function is called, and I want to resolve this
In this context, I intend to make a specific AnimMontage play
when the space bar is pressed
Here is My Code
CPlayer.cpp
ACPlayer::ACPlayer()
{
PrimaryActorTick.bCanEverTick = true;
bReplicates = true;
// CreateActorComponent
CHelpers::CreateActorComponent(this, &Montages, "Montages");
CHelpers::CreateActorComponent(this, &State, "State");
// ....
}
// Bind BeginPlay Function
void ACPlayer::OnEvade()
{
State->SetRollMode();
}
void ACPlayer::Begin_Roll()
{
bUseControllerRotationYaw = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
FVector start = GetActorLocation();
FVector end = start + GetVelocity().GetSafeNormal2D();
SetActorRotation(UKismetMathLibrary::FindLookAtRotation(start, end));
Montages->PlayRoll();
}
CStateComponent.h
private:
UFUNCTION(Server, Reliable)
void Server_ChangeStateType(EStateType InNewType, class AActor* DamageCauser = nullptr);
void Server_ChangeStateType_Implementation(EStateType InNewType, class AActor* DamageCauser = nullptr);
void ChangeType(EStateType InNewType, class AActor* DamageCauser = nullptr);
UFUNCTION(NetMulticast, Reliable)
void MC_ChangeStateType(EStateType InNewType, class AActor* DamageCauser = nullptr);
void MC_ChangeStateType_Implementation(EStateType InNewType, class AActor* DamageCauser = nullptr);
CStateComponent.cpp
void UCStateComponent::SetRollMode()
{
ChangeType(EStateType::Roll);
}
void UCStateComponent::ChangeType(EStateType InNewType, AActor* DamageCauser)
{
Server_ChangeStateType(InNewType, DamageCauser);
}
void UCStateComponent::MC_ChangeStateType_Implementation(EStateType InNewType, AActor* DamageCauser)
{
EStateType prevType = Type;
Type = InNewType;
if (OnStateTypePreChanged.IsBound())
OnStateTypePreChanged.Broadcast(prevType, Type, DamageCauser);
if (OnStateTypeChanged.IsBound())
OnStateTypeChanged.Broadcast(prevType, Type, DamageCauser);
}
OnStateTypeChanged Delegate Call ACPlayer::Begin_Roll()
And Function Call Montages->PlayRoll();
The following is same in flow and state to the existing one. PlayRoll() calls Server_PlayAnimMontage(), which in turn calls MC_PlayAnimMontage()
to propagate it to the clients
If there is not enough explanation for this code, you can check it on this GitHub.
Github Code
What steps should I take to resolve this issue, eliminate the warning, and get the replication working?
Thank you."