I’ve been working with multiplayer for a while now.
I’ve recently noticed that the “Get Remote Role” blueprint node is returning incorrect values when called on for example controller pawn/player controller.
From docs it is very clear that role of pawn on server should be ROLE Authority and on the client it should be ROLE Autonomous Proxy.
When called in blueprint it returns the other way around.
Has Authority will however return as expected with the client returning “False” and server “True”…
This is reproducible in a clean project.
If I’ve missed or misunderstood anything please enlighten me.
Remote role tells you the role of the “other” (or remote) computer. So if you’re the server the remote role is the client’s role and when you’re client the remote role is the server’s role. So you’re getting the correct values, GetRemoteRole is just confusing. I don’t think you can even just GetRole in BP which is very annoying.
My solution was to add the following static function to a StaticFunctionLibrary class that inherits from UObject:
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Actor.h"
#include "Engine/EngineTypes.h" // for ENetRole
#include "UMyStaticFunctionLibrary.generated.h"
UCLASS()
class [YourProject]_API UMyStaticFunctionLibrary : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Replication")
static ENetRole GetActorRole(const AActor* Actor)
{
if (IsValid(Actor))
{
return Actor->Role;
}
return ENetRole::ROLE_None;
};
};
Then you can call this function in any blueprint and plug self into it to get your actor’s role.