Casting GameSession not working

Hi ,

Your GameSession Class is spawned in GameMode::InitGame.
by calling ::GetGameSessionClass().

so you should have this overridden in your gamemode:

// Returns game session class to use 
TSubclassOf<AGameSession> AAbatronGameMode::GetGameSessionClass() const
{
	return AYOURGAMEGameSession::StaticClass();
}

Ensure that part is correct and put a break point there if you want to ensure of its creation!
Hope that helps!

Hi all,

I’ve been disecting the ShooterGame example and got to a stage where I have Steam OSS integrated and a UI to start hosting the game.

I have extracted the HostGame from the ShooterGame example and the Game Session.

My problem is the GameSession will not cast to my own GameSession which inherits from AGameSession.
(Line 19 below)

Here is the GetGameSession which is part of the GameInstance

ANDGSteamGameSession* UNDGStreamGameInstance::GetGameSession() const
{

	UWorld* const World = GetWorld();
	if (World)
	{
		AGameMode* const Game = World->GetAuthGameMode();
		if (Game)
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("GameMode Found"));

			AGameSession* session = Game->GameSession;
			if (session)
			{
				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Session Found"));
				//session->host
				
				ANDGSteamGameSession* ndgsteamGameSession;
				ndgsteamGameSession = Cast<ANDGSteamGameSession>(session);
				if (ndgsteamGameSession)
				{
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Casted To NDGSteamGameSession"));

					return ndgsteamGameSession;
				}
				else
				{
					GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Failed To Cast To NDGSteamGameSession"));
					return nullptr;
				}

			}
			else
			{
				GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Session NOT Found"));
			}
		}
	}

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("GameMode NOT Found"));
	return nullptr;
}

All the code is working apart from the line

ndgsteamGameSession = Cast<ANDGSteamGameSession>(session);

I’m not sure why this is happening or if there is something inside the NDGSteamGameSession I should implement and I’ve just simply missed it.

Thanks.

Thank you Devero,

This worked a charm,

I had to create a GameMode in c++ and copy over everything I had in the Blueprint thankfully this wasn’t alot.

I can continue with the project now.

Appreciate it.