I need to update the session before changing cards, but when I try to do it, I get the error “NO REGISTERED SESSIONS!”.
How to update session? Tell me, please.
The session is not registered because you’re playing in editor (tip make a quit game on succsess or on failure so you can check wether th update fails or not)
The session is valid, call a isvalid node on the session blueprint result when you join session, it will say valid. And ALL options work. The problem is, it works on the client, the server for some reason always returns invalid session state.
So…the client can find the session and potential call “updateSession” but that’s not a valid scenario ahaha.
I’m getting some info on this.
Well, I actually need to do this now. I have the solution if you or anyone needs it.
You will need to fix the ClassName.
.h
#pragma once
#include "CoreMinimal.h"
#include "Engine/Engine.h"
#include "GameFramework/PlayerState.h"
#include "Interfaces/OnlineSessionInterface.h"
#include "OnlineSessionSettings.h"
#include "OnlineDelegateMacros.h"
#include "OnlineSubsystem.h"
#include "OnlineSubsystemImpl.h"
#include "OnlineSubsystemUtils.h"
#include "OnlineSubsystemUtilsModule.h"
#include "GameFramework/PlayerController.h"
#include "OnlineSubsystemUtilsClasses.h"
#include "UObject/CoreOnline.h"
class APlayerController;
class IOnlineSubsystem;
// Couldn't use the default one as it is not exposed to other modules, had to re-create it here
// Helper class for various methods to reduce the call hierarchy
struct FHBGOnlineSubsystemBPCallHelper
{
public:
FHBGOnlineSubsystemBPCallHelper(const TCHAR* CallFunctionContext, UWorld* World, FName SystemName = NAME_None)
: OnlineSub(Online::GetSubsystem(World, SystemName))
, FunctionContext(CallFunctionContext)
{
if (OnlineSub == nullptr)
{
FFrame::KismetExecutionMessage(*FString::Printf(TEXT("%s - Invalid or uninitialized OnlineSubsystem"), FunctionContext), ELogVerbosity::Warning);
}
}
void QueryIDFromPlayerController(APlayerController* PlayerController)
{
UserID.Reset();
//return const_cast<FUniqueNetId*>(UniqueNetIdPtr);
if (APlayerState* PlayerState = (PlayerController != NULL) ? PlayerController->PlayerState : NULL)
{
UserID = PlayerState->GetUniqueId().GetUniqueNetId();
if (!UserID.IsValid())
{
FFrame::KismetExecutionMessage(*FString::Printf(TEXT("%s - Cannot map local player to unique net ID"), FunctionContext), ELogVerbosity::Warning);
}
}
else
{
FFrame::KismetExecutionMessage(*FString::Printf(TEXT("%s - Invalid player state"), FunctionContext), ELogVerbosity::Warning);
}
}
bool IsValid() const
{
return UserID.IsValid() && (OnlineSub != nullptr);
}
public:
//TSharedPtr<const FUniqueNetId>& GetUniqueNetId()
TSharedPtr</*class*/ const FUniqueNetId> UserID;
IOnlineSubsystem* const OnlineSub;
const TCHAR* FunctionContext;
};
#define INVALID_INDEX -1
This works in editor.
In any function you want to update the settings use this.
FHBGOnlineSubsystemBPCallHelper Helper(TEXT("UpdateSession"), GEngine->GetWorldFromContextObject(GetWorld(), EGetWorldErrorMode::LogAndReturnNull));
Helper.QueryIDFromPlayerController(GetOwningPlayer());
if (Helper.IsValid())
{
auto Session = Helper.OnlineSub->GetSessionInterface();
if (Session.IsValid())
{
FOnlineSessionSettings* settings = Session->GetSessionSettings(*GI->serverName);
if (settings)
{
UE_LOG(LogTemp, Warning, TEXT("settings ok"));
settings->NumPublicConnections = 50;
bool success = Session->UpdateSession(*GI->serverName, *settings, true);
if (success)
{
UE_LOG(LogTemp, Warning, TEXT("update success"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("update fail"));
}
}
}
}
It just updates playerCount for an example, but all works in editor.