플러그인 다듬기

개발 일지|2024. 12. 3. 22:11

MenuUI 클래스에 로비 경로를 추가해 레벨 이동이 하드코딩되있던 부분을 수정

	UFUNCTION(BlueprintCallable)
	void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll")), FString LobbyPath = FString(TEXT("/Game/FirstPerson/Maps/Lobby")));
    
    FString PathToLobby{TEXT("")};

간단하게 FString 변수를 추가하고, MenuSetup 선언부에 LobbyPath 추가

PathToLobby = FString::Printf(TEXT("%s?listen"), *LobbyPath);

UWorld* World = GetWorld();
if (World) {
	World->ServerTravel(PathToLobby);
}

MenuSetup 함수에 LobbyPath를 listen 옵션으로 지정해주고, CreateSession의 ServerTravel 로직을 변경해준다.

 

이렇게 하면 간단하게 변경 완료

 


 

다른 게임에 참여한 후, 호스트가 강제종료해 세션에서 나와진 후 일시적으로 Host가 되지 않는 버그

auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
if (ExistingSession != nullptr) {
	SessionInterface->DestroySession(NAME_GameSession);
}
  • CreateSession 로직 맨 위의 이미 존재하는 세션을 검사해 세션을 닫는 부분이 있는데, 네트워크 응답에 시간이 필요하나 바로 CreateSession의 다음 로직으로 넘어가 발생하는 문제
  • DestroySession을 거쳐 세션이 이미 있는경우 세션을 없애고, 세션이 없다면 마지막에 저장된 변수를 사용해 세션을 생성하도록 변경
void UMultiplayerSessionsSubsystem::DestroySession()
{
	if (!SessionInterface.IsValid()) {
		MultiplayerOnDestroySessionComplete.Broadcast(false);
		return;
	}
	DestroySessionCompleteDelegateHandle = SessionInterface->AddOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegate);

	if (!SessionInterface->DestroySession(NAME_GameSession)) {
		SessionInterface->ClearOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegateHandle);
		MultiplayerOnDestroySessionComplete.Broadcast(false);
	}
}


void UMultiplayerSessionsSubsystem::OnDestroySessionComplete(FName SessionName, bool bWasSuccessful)
{
	if (SessionInterface) {
		SessionInterface->ClearOnDestroySessionCompleteDelegate_Handle(DestroySessionCompleteDelegateHandle);
	}
	if (bWasSuccessful && bCreateSessionOnDestroy) {
		bCreateSessionOnDestroy = false;
		CreateSession(LastNumPublicConnections, LastMatchType);
	}
	MultiplayerOnDestroySessionComplete.Broadcast(bWasSuccessful);
}
  • CreateSession에서는 세션 생성에 필요한 값을 먼저 저장해두고, DestroySession을 호출해 검사할 수 있도록 변경
auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
if (ExistingSession != nullptr) {
	bCreateSessionOnDestroy = true;
	LastNumPublicConnections = NumPublicConnections;
	LastMatchType = MatchType;

	DestroySession();
}

 


Quit 버튼

  • 그냥 간단하게 메뉴 widget BP에 버튼 하나 만들어주고, OnClicked 이벤트에 Quit 노드 연결

메뉴 버튼 활성화 및 비활성화

  • 여러번 Host 버튼을 누르는걸 막아 중복 세션 생성을 막기 위함
  • 모종의 이유로 Host에 실패했거나, 세션 참가에 실패했을 때 버튼을 다시 활성화
  • SetIsEnabled 옵션을 true나 false로 두고 적절한 위치에 배치.

 

 

'개발 일지' 카테고리의 다른 글

Tracking Player  (0) 2024.12.03
플러그인 UI - 2  (0) 2024.12.02
플러그인 UI - 1  (0) 2024.12.01
플러그인 등록  (0) 2024.11.30
Join Session  (0) 2024.11.29

댓글()