Unreal Engine/Trouble Shooting

AGameMode::RestartGame() 이슈 및 프로젝트 버전 업데이트

SB_J00N 2024. 2. 4. 00:13

엔진 버전 : 5.0.3

Online Subsystem : Steam

Listen Server

Packaged, PIE 둘다 해당

void ABlasterGameMode::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (MatchState == MatchState::WaitingToStart)
	{
		//UE_LOG(LogTemp, Warning, TEXT("%f, %f, %f"), WarmupTime, LevelStartingTime, GetWorld()->GetTimeSeconds());
		CountdownTime = WarmupTime + LevelStartingTime - GetWorld()->GetTimeSeconds();
		if (CountdownTime <= 0.f)
		{
			StartMatch();
		}
	}
	else if (MatchState == MatchState::InProgress)
	{
		CountdownTime = WarmupTime + MatchTime + LevelStartingTime - GetWorld()->GetTimeSeconds();
		if (CountdownTime <= 0.f)
		{
			SetMatchState(MatchState::Cooldown);
		}
	}
	else if (MatchState == MatchState::Cooldown)
	{
		CountdownTime = WarmupTime + MatchTime + LevelStartingTime + CooldownTime - GetWorld()->GetTimeSeconds();
		if (CountdownTime <= 0.f)
		{
			RestartGame();
		}
	}
}

 

위와같이 Cooldown으로 MatchState를 설정하고 CooldownTime 만큼 시간이 지나면 ReStartGame()을 호출한다.

ABlasterGameMode는 AGameMode의 파생 Class이며 RestartGame 함수는 아래와 같다.

/** Restart the game, by default travel to the current map */
UFUNCTION(BlueprintCallable, Category="Game")
virtual void RestartGame();

void AGameMode::RestartGame()
{
	if ( GameSession->CanRestartGame() )
	{
		if (GetMatchState() == MatchState::LeavingMap)
		{
			return;
		}

		GetWorld()->ServerTravel("?Restart",GetTravelType());
	}
}

 

허나 패키지 버전, PIE 모두 테스트 결과 서버(리슨 서버임으로 서버역할을 하는 클라이언트)에서는 RestartGame을 올바르게 호출하여 게임을 재시작하나, 클라이언트에서는 RestartGame()이 실행되지 않는다. 

 

원인은 Steam Online Subsystem을 앤진 5.0.3 버전에서 이용시 발생한다.

(아마도) 다른 서브시스템에선 RestartGame()이 정상적으로 작동되는 것으로 보임.

 

해결방법

1. ServerTravel 이용

RestartGame 대신에 직접 ServerTravel을 이용하여 맵을 로드해준다.

 

2. 프로젝트 버전 업데이트

https://docs.unrealengine.com/5.2/en-US/updating-projects-to-newer-versions-of-unreal-engine/

 

Updating Projects to Newer Versions of Unreal Engine

Learn how to update projects to a newer version of Unreal Engine.

docs.unrealengine.com

 

5.0.3에서 5.1.1 (또는 더 최신인 버전)으로 업데이트를 하면 해결된다.

만약에 위와 같은 가이드대로 진행하는데 컴파일 에러가 발생하여 업데이트가 완료된 것이 아니라,

업데이트 진행 자체가 '권한'같은 키워드 관련해 오류가 발생해 진행되지 않는다면 아래를 참고하면 좋을 것 같다.

 

https://www.epicgames.com/help/ko/c5719341124379/c5719359691291/dp-01-a5720353617435?sessionInvalidated=true

 

업데이트시 주의사항

1. OnLevelRemovedFromWorld 사용 불가

5.1.1 부터는 OnLevelRemovedFromWorld가 삭제되었다. 대신에 NativeDestruct()를 사용하면 된다.

Input Parameter는 없다.

UUserWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)

UUserWidget::NativeDestruct()

https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215

 

Where is UUserWidget::OnLevelRemovedFromWorld in 5.1

UUserWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld) I tried to migrate from 5 to 5.1 and noticed this function has been removed. any function that can replace it?

forums.unrealengine.com

 

2. DefaultGame.ini 파일에대한 코딩 표준 경고

https://docs.unrealengine.com/5.0/en-US/epic-cplusplus-coding-standard-for-unreal-engine/

 

Coding Standard

Write maintainable code by adhering to established standards and best practices.

docs.unrealengine.com

Racial, ethnic, and religious inclusiveness
Do not use metaphors or similes that reinforce stereotypes.
This includes those that contrast black and white, such as blacklist / whitelist.
Do not use words that refer to historical trauma or lived experience of discrimination.
This includes slave, master, and nuke

 

코딩 표준에 근거하여 5.0.3 에서는 (아마도) 경고는 띄우지 않았는데,

5.1.1 버전으로 업데이트시 ini 파일이 변경되지않고 그대로 이주되어 컴파일 시 경고메시지를 띄운다.

(단 오류가 발생하진 않고 경고메시지에서 끝나는 것으로 보인다)

 

현재 프로젝트에서는  컴파일시 일단 DefaultGame.ini에서만 경고를 띄어서 직접 수정하였다.

예를들어 -IniKeyBlacklist=KeyStorePassword 에서 IniKeyDenylist=KeyStorePassword으로 수정하였다.

3. vcxproj 파일을 찾을 수 없음. 프로젝트를 로드할 수 없음 등

기존 프로젝트에서 비주얼 스튜디오를 소스 코드 에디터로 사용하다가 버전 업데이트 후, 솔루션 파일을 실행했을 때 vcxproj 파일이 없다면서 vs에서 프로젝트 로드가 안될 때 해결방법이다.

(vcxproj와 관련 파일들은  ProjectFolder\Intermediate\ProjectFiles) 안에 있어야 한다.)

 

(아주 간단하게 해결가능한데 기본 지식이 부족하고 검색해도 제대로 나오질 않아 오래 걸렸다 ^^...)

 

아마 소스 코드 에디터가 Visual Studio Code로 되어있을 것이다. 따라서 vcxproj파일이 없고 에디터에서 C++ 클래스를 클릭했을 때 vs code로 해당 클래스가 열릴 것이다. (대신에 프로젝트 폴더안에 vscode 폴더가 있을 것이다.)

 

아주 간단하게 Visual Studio Code로 변경 후에 에디터,  vs, vscode 모두 닫고 Binaries, Intermediate, Saved 폴더를 삭제후 uproject 파일 우클릭 -> Generate visual studio file을 해주면 정상적으로 해결될 것이다.

 

또 검색하다가 찾은 것이 경로의 길이가 약 260자이상이 되는 경우에도 오류가 발생할 수 있다고도 한다.

사실 개인 pc로 프로젝트를 할 때는 260자 까지 되긴 좀 힘들어 보이긴 하나 참고하면 좋을 것 같다.

https://forums.unrealengine.com/t/vcxproj-project-can-not-be-loaded/287258

 

Vcxproj - project can not be loaded

For me this is 100% repetable bug. Engine 4.2.1 both versions, I mean with sources and compiled one. I lunch editor, create new c++ project, then editor closes automatically and VS opens. I got my project and solution, then I close VS and try to reopen pro

forums.unrealengine.com