Loading the catalog…
Loading the catalog…
이전 단계에서는 Unreal Engine Multiplayer의 Server/Client 구조와 Game Framework를 학습하였다. 이번에는 실제로 Client에서 입력한 내용을 Server로 보내고 다른 Player에게도 전달하는 Multiplayer Chat 을 구현하였다. 이 과정에서 가장 중요하게 학습한 개념은 RPC였다. 📡 RPC Multiplayer에서는 함수가 실행되는 위치가 중요하다. 이번 과정에서는 다음과 같은 RPC 구조를 학습하였다. Server RPC Client RPC NetMulticast RPC 🖥 Server RPC Client에서 Server에게 작업을 요청할 때 사용한다. Client ↓ Server RPC ↓ Server 이후 숫자 야구에서도 Player가 입력한 값을 Server로 전달하는 데 이 구조를 사용하게 된다. 👤 Client RPC Server에서 특정 Client에게 결과를 전달할 때 사용할 수 있다. Server ↓ Client RPC ↓ Client 📢 NetMulticast RPC Server에서 실행된 내용을 여러 Client에게 전달할 때 사용할 수 있다. Server ↓ NetMulticast ↓ Client 1 Client 2 ... 여러 Player에게 같은 Message나 게임 상태를 알려야 할 때 사용할 수 있다. 💬 Multiplayer Chat 흐름 Chapter 1에서 제작한 WBP_NBChatInput 을 실제 Multiplayer 구조와 연결하였다. 전체적인 흐름은 다음과 같다. WBP_NBChatInput ↓ EditableTextBox_ChatInput ↓ Chat 입력 ↓ NBPlayerController ↓ Server RPC ↓ Server ↓ Message 처리 ↓ Client ↓ Chat UI 출력 이제 입력한 Text가 자신의 화면에서만 처리되는 것이 아니라 Server를 통해 Multiplayer 환경에서 전달된다. 🎮 NBPlayerController NBPlayerController 는 Player의 입력과 Server 통신을 연결하는 역할을 담당하였다. Player Input ↓ NBPlayerController ↓ Server RPC ↓ Server Widget 자체에서 Server의 게임 규칙을 직접 처리하지 않고 PlayerController를 통해 요청을 전달하는 구조를 사용하였다. 이 구조는 이후 숫자 야구에서도 그대로 사용된다. 🔔 OnPostLogin() 새로운 Player가 Server에 접속했을 때는 NBGameModeBase 의, OnPostLogin() 을 사용하였다. 새로운 PlayerController가 접속하면 NBPlayerController 로 Cast하고 연결된 PlayerController를 관리한다. Player 접속 ↓ NBGameModeBase::OnPostLogin() ↓ NBPlayerController Cast ↓ AllPlayerControllers 등록 📢 접속 Notification Player가 Server에 접속했다는 사실을 알려주기 위해 다음 메시지를 사용하였다. Connected to the game server. 전체 흐름은 다음과 같다. Player 접속 ↓ OnPostLogin() ↓ NBPlayerController ↓ NotificationText ↓ Connected to the game server. 이를 통해 OnPostLogin() 이 Multiplayer에서 Player가 접속한 직후 필요한 초기 설정을 수행할 수 있는 위치라는 것을 확인하였다. 👤 NBPlayerState Player마다 서로 다른 정보를 관리하기 위해 다음 클래스를 사용하였다. NBPlayerState Player 이름은, PlayerNameString 으로 관리하였다. 이를 이용하여 접속한 Player를, Player1 Player2 처럼 구분할 수 있도록 하였다. 이후 숫자 야구에서는 같은 PlayerState를 이용하여 각 Player의 시도 횟수도 따로 관리하게 된다. 💬 Chat Log와 History Chat UI에서는 Player가 입력한 메시지를 확인할 수 있도록 다음 Widget들을 사용하였다. TextBlock_ChatLog ScrollBox_ChatHistory 이를 통해 Multiplayer 환경에서 전달된 Chat 내용을 화면에서 확인할 수 있도록 구성하였다. 🔔 Notification Widget 연결 접속 알림과 이후 게임 결과를 표시하기 위해 Notification Widget도 연결하였다. PlayerController Blueprint에서 실제 Widget Class를 지정하였다. BP_NBPlayerController ↓ Notification Text Widget Class ↓ WBP_NotificationText C++에서 Notification 기능을 작성하더라도 Blueprint에서 실제 Widget Class를 지정하지 않으면 화면에 표시되지 않을 수 있다. 따라서, C++ 기능 구현 + Blueprint Widget Class 설정 = 실제 Notification 출력 이라는 연결 관계를 확인하였다. 🔗 C++과 Blueprint 이번 작업에서는 C++ 코드와 Blueprint 설정이 함께 사용되는 경우가 많았다. 예를 들어 BindWidget 에서는, C++ 변수 이름 + Blueprint Widget 이름 + Widget Type 이 일치해야 한다. Notification에서도, C++ Notification 기능 + Blueprint Widget Class 가 함께 있어야 실제 화면에 나타난다. Unreal Engine에서는 C++에서 기능을 작성하는 것과 Blueprint에서 해당 기능을 실제 Asset에 연결하는 작업이 모두 중요하다는 것을 다시 확인하였다. 🔄 Chat 구조를 게임 입력으로 확장 이번에 만든 Multiplayer Chat 구조는 이후 숫자 야구 게임에서도 그대로 활용하였다. Chat에서는, Player ↓ Text 입력 ↓ PlayerController ↓ Server RPC ↓ Server ↓ Message 전달 구조를 사용하였다. 숫자 야구에서는 이를, Player ↓ 3자리 숫자 입력 ↓ PlayerController ↓ Server RPC ↓ GameMode ↓ Number Baseball 판정 ↓ 결과 전달 구조로 확장하게 된다. 즉 Chat을 구현하면서 학습한 RPC 구조가 실제 Multiplayer 게임 로직의 기반이 되었다. 💡 이번 학습에서 배운 점 이번 작업에서는 RPC를 이용하여 Client와 Server가 실제로 데이터를 주고받는 구조를 학습하였다. 싱글플레이에서는, Input ↓ Function ↓ Result 만 생각하면 되지만 Multiplayer에서는, Client Input ↓ Server RPC ↓ Server ↓ Game Logic ↓ Result ↓ Client 처럼 실행 위치와 데이터 전달 과정을 함께 생각해야 한다. 또 각각의 Framework 클래스가 담당하는 역할도 조금 더 명확해졌다. NBPlayerController → Player 입력과 Server 요청 NBGameModeBase → Server의 게임 규칙 및 Player 접속 NBPlayerState → Player별 데이터 이번 Multiplayer Chat 구현을 통해 다음 단계에서 실제 숫자 야구 게임을 구현할 수 있는 네트워크 기반을 만들 수 있었다. 🌐💬
What RADAR observed and classified to build this opportunity. It is what the source published, not a verification that the offer is still active.
# 🌐 TIL | Unreal Engine C++ RPC를 이용한 Multiplayer Chat 구현. 이전 단계에서는 Unreal Engine Multiplayer의 Server/Client 구조와 Game Framework를 학습하였다. 이번에는 실제로 Client에서 입력한 내용을 Server로 보내고 다른 Player에게도 전달하는 Multiplayer Chat 을 구현하였다. 이 과정에서 가장 중요하게 학습한 개념은 RPC였다. 📡 RPC Multiplayer에서는 함수가 실행되는 위치가 중요하다. 이번 과정에서는 다음과 같은 RPC 구조를 학습하였다. Server RPC Client RPC NetMulticast RPC 🖥 Server RPC Client에서 Server에게 작업을 요청할…
Open source