728x90
반응형
스팀연결
1.온라인 서브시스템 활성화
플러그인->온라인 서브시스템 스팀 활성화->UE재시작
2.코드수정
build.cs에 "OnlineSubsystem","OnlineSubsystemSteam"추가
PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"HeadMountedDisplay"
});
//->서브시스템추가
PublicDependencyModuleNames.AddRange(new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"HeadMountedDisplay",
"OnlineSubsystemSteam",
"OnlineSubsystem"
});
3.DefaultEngine.ini 수정
Online Subsystem Steam
An overview of Online Subsystem Steam, including how to set up your project for distribution on Valve's Steam platform.
docs.unrealengine.com
엔진 맨밑에 코드 추가한다.
[/Script/Engine.GameEngine]
+NetDriverDefinitions=(DefName="GameNetDriver",DriverClassName="OnlineSubsystemSteam.SteamNetDriver",DriverClassNameFallback="OnlineSubsystemUtils.IpNetDriver")
[OnlineSubsystem]
DefaultPlatformService=Steam
[OnlineSubsystemSteam]
bEnabled=true
SteamDevAppId=480
bInitServerOnClient=true
[/Script/OnlineSubsystemSteam.SteamNetDriver]
NetConnectionClassName="OnlineSubsystemSteam.SteamNetConnection"
※주의
; If using Sessions
; bInitServerOnClient=true
//언리얼 문서의 이부분을 그대로 치면 작동하지 않으므로
bInitServerOnClient=true
//으로 고쳐적어야함
4.온라인 서브시스템 엑세스
IOnlineSubsystem
OnlineSubsystem - Series of interfaces to support communicating with various web/platform layer services
docs.unrealengine.com
//Character.h
#include "Interfaces/OnlineSessionInterface.h"
UCLASS(config=Game)
class _Character : public ACharacter
{
public:
IOnlineSessionPtr OnlineSessionInterface;
}
//Character.cpp
_Character::_Character()
{
IOnlineSubsystem* OnlineSubsystem= IOnlineSubsystem::Get();
if (OnlineSubsystem)
{
OnlineSessionInterface=OnlineSubsystem->GetSessionInterface();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage
(-1, 15.f, FColor::Red,
FString::Printf(TEXT("Online: %s"),
*OnlineSubsystem->GetSubsystemName().ToString())
);
}
}
}
5.델레게이트와 콜백함수 설정
//Character.h
protected:
UFUNCTION(BlueprintCallable)
void CreateGameSession();
void OnCreateSessionComplete(FName SessionName,bool bWasSuccessful);
private:
FOnCreateSessionCompleteDelegate CreateSessionCompleteDelegate;
//Character.cpp
_Character::_Character():
CreateSessionCompleteDelegate(FOnCreateSessionCompleteDelegate::CreateUObject(this,&ThisClass::OnCreateSessionComplete))
{
}
6.세션만들기
FOnlineSessionSettings
Container for all settings describing a single online session
docs.unrealengine.com
//Character.cpp
#include "OnlineSessionSettings.h"
void _Character::CreateGameSession()
{
if (!OnlineSessionInterface.IsValid())return;
auto ExitSession=OnlineSessionInterface->GetNamedSession(NAME_GameSession);
if (ExitSession != nullptr)OnlineSessionInterface->DestroySession(NAME_GameSession);
OnlineSessionInterface->AddOnCreateSessionCompleteDelegate_Handle(CreateSessionCompleteDelegate);
TSharedPtr<FOnlineSessionSettings>SessionSettings=MakeShareable(new FOnlineSessionSettings());
SessionSettings->bIsLANMatch = false;
SessionSettings->NumPublicConnections = 4;
SessionSettings->bAllowJoinInProgress = true;
SessionSettings->bAllowJoinViaPresence = true;
SessionSettings->bShouldAdvertise = true;
SessionSettings->bUsesPresence = true;
const ULocalPlayer* LocalPlayer=GetWorld()->GetFirstLocalPlayerFromController();
OnlineSessionInterface->CreateSession(*LocalPlayer->GetPreferredUniqueNetId(),NAME_GameSession,*SessionSettings);
}
7.세션 테스트
//Character.cpp
void _Character::OnCreateSessionComplete(FName SessionName, bool bWasSuccessful)
{
if (bWasSuccessful)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Blue,
FString::Printf(TEXT("Success CreateSession:%s"),*SessionName.ToString()));
}
}
else
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 15.f, FColor::Red,
FString::Printf(TEXT("Faild CreateSession")));
}
}
}
728x90
반응형
'UE5 > UE5 MultiPlayerGame' 카테고리의 다른 글
MultiPlayerGame) 6. 세션에 참여 (0) | 2022.06.04 |
---|---|
MultiPlayerGame) 5. 참가세션 만들기 (0) | 2022.06.03 |
MultiPlayerGame)3.온라인 서브시스템 (0) | 2022.05.31 |
MultiPlayerGame)2.LAN 연결 (0) | 2022.05.30 |
MultiPlayerGame)1.멀티플레이의 개념 (0) | 2022.05.30 |
댓글