[UE5] Actor Role, Remote Role

kkado·2024년 6월 14일
0

UE5

목록 보기
42/62
post-thumbnail

네트워크 게임플레이에서 액터의 roleremote role'이 액터의 상태를 변경하거나 RPC를 수행할 권한이 어느 기기에 있는가 를 결정한다.

이 프로퍼티들은 다음 세 가지 질문의 답을 하는데 도움을 준다.

  • 이 액터가 복제된 것인가 아닌가?
  • 누구에게 이 액터의 권한이 있는가?
  • 이 액터의 replication role이 무엇인가?

View Actor Role

액터를 클릭 후 디테일 패널을 살펴보면 이 액터의 role을 알 수 있다. 또는 다음과 같이 메서드 호출을 통해서 얻을 수 있다.

AActor* MyActor;

const ENetRole LocalRole = MyActor->GetLocalRole();
const ENetRole RemoteRole = MyActor->GetRemoteRole();

Actor Role States

Actor Role과 Remote Role은 ENetRole enum 클래스로 표현된다.

ROLE_None

  • 역할 없음. 이 액터는 복제되지 않음.

ROLE_SimulatedProxy

  • 액터의 Simulated Proxy. 즉 다른 클라이언트의 원격 제어를 받는 액터. 상태를 변경하거나 원격 함수를 호출할 수 없음.

ROLE_AutonomousProxy

  • 내가 직접 컨트롤하는 액터. 상태를 변경하거나 원격 함수를 호출 가능.

ROLE_Authority

  • 서버 측에서 Authority를 갖는 액터. 이 액터는 프로퍼티의 변경을 추적하고, 다른 연결된 클라이언트에게 전달하는 역할까지 수행함.

직접 확인

예시 환경

플레이어 캐릭터의 머리 위에 HUD 텍스트로 Role을 출력해서 직접 확인해보자.

UUserWidget 타입의 'OverheadWidget' 클래스를 만들고 UTextBlock 을 부착한다.

OverheadWidget.h

UCLASS()
class BLASTER_API UOverheadWidget : public UUserWidget
{
	GENERATED_BODY()
	
public:
	UPROPERTY(meta = (BindWidget))
	class UTextBlock* DisplayText;

	void SetDisplayText(FString TextToDisplay);

	UFUNCTION(BlueprintCallable)
	void ShowPlayerNetRole(APawn* InPawn);
};

OverheadWidget.cpp

void UOverheadWidget::SetDisplayText(FString TextToDisplay)
{
    if (DisplayText)
    {
        DisplayText->SetText(FText::FromString(TextToDisplay));
    }

}

void UOverheadWidget::ShowPlayerNetRole(APawn* InPawn)
{
    ENetRole LocalRole = InPawn->GetLocalRole();
    ENetRole RemoteRole = InPawn->GetRemoteRole();
    FString Role;

    switch (LocalRole)
    // switch (RemoteRole)
    {
        case ENetRole::ROLE_Authority:
            Role = FString("Authority");
            break;

        case ENetRole::ROLE_AutonomousProxy:
            Role = FString("Autonomous Proxy");
            break;

        case ENetRole::ROLE_SimulatedProxy:
            Role = FString("Simulated Proxy");
            break;
        
        default:
            Role = FString("None");
            break;
    }

    FString LocalRoleString = FString::Printf(TEXT("Local Role : %s"), *Role);
    FString RemoteRoleString = FString::Printf(TEXT("Remote Role : %s"), *Role);
    SetDisplayText(LocalRoleString);
    //SetDisplayText(RemoteRoleString);
}

GetLocalRole(), GetRemoteRole() 함수를 통해 각각의 Role을 알 수 있고 이를 switch 구문을 거쳐 머리 위에 출력할 텍스트를 생성한다.

그리고 3명의 플레이어를 생성하고, Net Mode를 'Play As Listen Server' 로 한다.

Local Role

먼저 listen server 쪽을 살펴보면, 컨트롤하고 있는 캐릭터 이외에도 모든 캐릭터의 local role이 Authority 인 것을 확인할 수 있다.

이 클라이언트는 클라이언트이자 서버이다. 즉 모든 캐릭터의 Authority를 가지고 있다.

반면 클라이언트는 내가 컨트롤하면서 소유하고 있는 캐릭터는 Autonomous Proxy 권한을 갖고 있고, 나머지 캐릭터들은 모두 Simulated Proxy 권한을 가지고 있음을 확인할 수 있다.

Remote Role

주석처리를 수정해서 Remote Role을 머리 위에 뜨도록 수정

서버에서 확인해 보면 조종하고 있는 캐릭터는 Autonomous Proxy, 나머지 캐릭터는 Simulated Proxy 권한을 가지고 있다.

반대로 한 클라이언트에서 확인해 보면 모두가 Authority 권한을 가지고 있다.

Local role을 나타낸 그림


참고 자료

https://dev.epicgames.com/documentation/en-us/unreal-engine/actor-role-and-remote-role-in-unreal-engine

profile
울면안돼 쫄면안돼 냉면됩니다

0개의 댓글