728x90
반응형
1.JoinGameSession만들기
//Character.h
protected:
UFUNCTION(BlueprintCallable)
void JoinGameSession();
void OnFindSessionComplete(bool bWasSuccessful);
2.델레게이트와 콜백설정
/Character.h
protected:
void OnFindSessionComplete(bool bWasSuccessful);
private:
FOnFindSessionsCompleteDelegate FindSessionCompleteDelegate;
TSharedPtr<FOnlineSessionSearch>SessionSearch;
//Character.cpp
_Character::_Character():
FindSessionCompleteDelegate(FOnFindSessionsCompleteDelegate::CreateUObject(this,&ThisClass::OnFindSessionComplete))
{
}
3.검색세션 세팅
FOnlineSessionSearch
Encapsulation of a search for sessions request.
docs.unrealengine.com
//Character.cpp
void _Character::JoinGameSession()
{
if (!OnlineSessionInterface.IsValid())return;
OnlineSessionInterface->AddOnFindSessionsCompleteDelegate_Handle(FindSessionCompleteDelegate);
SessionSearch=MakeShareable(new FOnlineSessionSearch());
SessionSearch->MaxSearchResults = 10000;
SessionSearch->bIsLanQuery = false;
SessionSearch->QuerySettings.Set(SEARCH_PRESENCE,true ,EOnlineComparisonOp::Equals);
const ULocalPlayer* LocalPlayer = GetWorld()->GetFirstLocalPlayerFromController();
OnlineSessionInterface->FindSessions(*LocalPlayer->GetPreferredUniqueNetId(),SessionSearch.ToSharedRef());
}
4.테스트
void _Character::OnFindSessionComplete(bool bWasSuccessful)
{
for (auto Result : SessionSearch->SearchResults)
{
FString Id = Result.GetSessionIdStr();
FString USer = Result.Session.OwningUserName;
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Cyan,
FString::Printf(TEXT("ID:%s, User:%s"),*Id,*USer));
}
}
}
//Character.cpp
void _Character::CreateGameSession()
{
SessionSettings->bUseLobbiesIfAvailable = true;//추가
}
728x90
반응형
'UE5 > UE5 MultiPlayerGame' 카테고리의 다른 글
MultiPlayerGame) 7. 플러그인 생성 (0) | 2022.06.07 |
---|---|
MultiPlayerGame) 6. 세션에 참여 (0) | 2022.06.04 |
MultiPlayerGame) 4. 스팀연결 (0) | 2022.06.02 |
MultiPlayerGame)3.온라인 서브시스템 (0) | 2022.05.31 |
MultiPlayerGame)2.LAN 연결 (0) | 2022.05.30 |
댓글