I’m working on replicating a weapon class and using ShooterGame as an example, but I’m running to some issues and I wanted to see if I could get some clarification on what the proper roles for each party should be. In the examples you see things like:
if (Role < ROLE_Authority)
{
ServerCall();
}
The only problem is that this isn’t working for me, because when I run from the editor both the listen server and the client are running as ROLE_Authority. If I check into RemoteRole it says that it is ROLE_SimulatedProxy. Which seems completely backwards based on the examples.
The reason I bring this up is because I’m trying to wrap my head around why this isn’t working at all for me, and I have a feeling that whatever I’m missing is causing the roles to be wrong. My issue is that client → server calls aren’t working at all. I tried changing my code to do something like this:
if (GetNetMode() == NM_Client)
{
ServerStartFire();
}
And verified that it was executing that block, but it still doesn’t seem to execute ServerStartFire_Implementation.
That being said, the replication from the listen server to the client is working fine. So, in my case, I’m able to see the shots replicated on the client, but not the other way around.
Thanks!
EDIT
I tried to start over with a new Actor to see if I could have done something wrong while implementing my weapon class, but the problem still exists here. Here’s the code of the new class:
Example.h
#pragma once
#include "GameFramework/Actor.h"
#include "Example.generated.h"
/**
*
*/
UCLASS()
class AExample : public AActor
{
GENERATED_UCLASS_BODY()
UFUNCTION()
void Call();
UFUNCTION(Server, Reliable, WithValidation)
void ServerCall();
};
Example.cpp
#include "Mach.h"
#include "Example.h"
AExample::AExample(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
bReplicates = true;
bAlwaysRelevant = true; // Had to add this because it was complaining about no root component
}
void AExample::Call()
{
UE_LOG(LogTemp, Log, TEXT("Example Call"));
switch (Role)
{
case ROLE_None:
UE_LOG(LogTemp, Log, TEXT("ROLE_None"));
break;
case ROLE_SimulatedProxy:
UE_LOG(LogTemp, Log, TEXT("ROLE_SimulatedProxy"));
break;
case ROLE_AutonomousProxy:
UE_LOG(LogTemp, Log, TEXT("ROLE_AutonomousProxy"));
break;
case ROLE_Authority:
UE_LOG(LogTemp, Log, TEXT("ROLE_Authority"));
break;
case ROLE_MAX:
UE_LOG(LogTemp, Log, TEXT("ROLE_MAX"));
break;
}
ServerCall();
}
bool AExample::ServerCall_Validate()
{
return true;
}
void AExample::ServerCall_Implementation()
{
UE_LOG(LogTemp, Log, TEXT("Server call implementation"));
}
Then in my Character class I added the following in PostInitializeComponents
:
FActorSpawnParameters SpawnInfo;
Example = GetWorld()->SpawnActor<AExample>(AExample::StaticClass(), SpawnInfo);
And then added the call in OnStartFire
which is bound to Fire:
Example->Call();
Here’s what the logs show:
[2014.05.23-22.54.30:644][551]LogTemp: Example Call
[2014.05.23-22.54.30:644][551]LogTemp: ROLE_Authority