첫번째 트러블 상황
BaseInGameHUD에서 정의한 GetTogglePauseWidget을 PlayerController에서 가져오기 위해 IsValid로 값체크를 하는 과정에서 발생.
이유
IsValid()는 UObject* 타입을 요구하는데 GetTogglePauseWidget()은 const 포인터를 반환하고 있음. IsValid()는 주로 non-const 버전을 검사하게 구현되어있어서 생기는 문제.
해결방법
UFUNCTION(BlueprintCallable, Category = "CCFF|UI")
FORCEINLINE UTogglePauseWidget* GetTogglePauseWidget() const { return TogglePauseWidget; }
IsValid()를 쓰지않고 ≠nullptr로 바꿔줘서 해결
두번째 트러블 상황
void UTrainingWidget::UpdateTimer()
{
CurrentTime -= 1.0f;
if (CurrentTime <= 0.0f)
{
CurrentTime = 0.0f;
GetWorld()->GetTimerManager().ClearTimer(TimerHandle);
}
int32 Minutes = FMath::FloorToInt(CurrentTime / 60.0f);
int32 Seconds = FMath::FloorToInt(CurrentTime) % 60;
FString FormattedTime = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
UpdateTimerText(FormattedTime);
}
이런 구조로 가는데 Base의 TimerText가 업데이트되지 않았다.
이유 및 해결 방법
void UTrainingWidget::UpdateTimer()
{
CurrentTime -= 1.0f;
if (CurrentTime <= 0.0f)
{
CurrentTime = 0.0f;
GetWorld()->GetTimerManager().ClearTimer(TimerHandle);
}
int32 Minutes = FMath::FloorToInt(CurrentTime / 60.0f);
int32 Seconds = FMath::FloorToInt(CurrentTime) % 60;
FString FormattedTime = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
if (APlayerController* PC = GetOwningPlayer())
{
if (ABaseInGameHUD* HUD = Cast<ABaseInGameHUD>(PC->GetHUD()))
{
if (UBaseInGameWidget* BaseWidget = HUD->GetBaseInGameWidget())
{
BaseWidget->UpdateTimerText(FormattedTime);
}
}
}
}
TrainingWidget에서는 직접 TimerText를 갖지 않고, 대신 현재 HUD에 있는 BaseInGameWidget의 UpdateTimerText() 함수를 호출해서 타이머 텍스트를 갱신하는 게 내 예상 결과값이었다.
즉, TrainingWidget 내부에서 "this->UpdateTimerText(...)"를 호출하면 TrainingWidget 자체의 (없거나 null인) TimerText에 업데이트가 적용된다고 한다. 그래서 대신, HUD에 있는 BaseInGameWidget 인스턴스를 찾아서 그 인스턴스의 UpdateTimerText()를 호출해주는 방식으로 수정해주었다.
마지막 말
오늘 타이머 작업을 하다가 아무래도 위젯클래스에서 로직을 타는게 좀 이상하다고 생각이 들었다..
그리고 GameMode와 GameState의 역할? 분리를 어떻게 해야할지 감을 못잡고 작업하는 상태여서 계속 하면서 이상하다는 생각을 했다..
아니나다를까.. 이상한 구조로 작업하고 있어서 아예 구조를 전면변경하려고 한다..
눈에서 무슨 액체가 흐른다..
'Unreal Engine' 카테고리의 다른 글
[ UE, C++ ] 네트워크 환경에서 클라이언트 카메라 전환시키기 (0) | 2025.04.21 |
---|---|
[ UE ] TrainingMode 및 UI 구현 (0) | 2025.04.08 |
[ UE ] 위젯과 타이머 연동하기 (0) | 2025.04.04 |
[ UE ] 훈련장모드 베이스 설계 (0) | 2025.04.03 |
[ UE ] 데디케이트 서버 패키징을 해보자 (1) | 2025.03.31 |