SlotName does not travel!

vr2_s02_parsing_level_options_in_gamemode

#1

Hi I face new problem in the ParseOption() and it doesn’t work I have tested with course GitHub Repo and my code exactly same as GitHub code but I have no idea why it doesn’t work in UE4.20.I must add I can get SlotName in the Painting GridCard
UGameplayStatics::OpenLevel(GetWorld(), TEXT("TestMap"), true, "SlotName=" + PaintingName);

but when I want to use it in the Gamemode it returns null and my init code is same as tutrial:

void UPaintingGridCard::SetPaintingName(FString NewPaintingName)
{
	PaintingName = NewPaintingName;
	SlotName->SetText(FText::FromString(PaintingName));
	CardButton->OnClicked.AddDynamic(this, &UPaintingGridCard::CardButtonClicked);
		

}

#2

I’m wondering how @sampattuzzi can get SlotName as an option in the gameModeBase ()? Options Receive in the InitGame() function and it runs and initialize before all components so how it possible click on PaintingGridCard and get options?Options are null and they receive after clicking.:thinking::thinking:


#3

Where is the code that receives the options in the new level?


#4

the code receives an option in the gamemode in the initgame, isn’t true?


#5

Yeah, I was wondering if you could share your code for that part?


#6

Yes of course
gameMode and also paintinggridcardPreformatted text

// Fill out your copyright notice in the Description page of Project Settings.

#include "PaintingGameMode.h"
#include "Kismet/GameplayStatics.h"
#include "Saving/PainterSaveGame.h"
#include "Kismet/StereoLayerFunctionLibrary.h"


void APaintingGameMode::InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage)
{
	Super::InitGame(MapName, Options, ErrorMessage);
	SlotName = UGameplayStatics::ParseOption(Options, "SlotName");

	UE_LOG(LogTemp, Warning, TEXT("SlotName: %s"), *SlotName);

}

void APaintingGameMode::BeginPlay()
{
	Super::BeginPlay();

	UPainterSaveGame* Saving = UPainterSaveGame::Load(SlotName);
	if (Saving) 
	{
		Saving->DeSerilizeToWorld(GetWorld());
		UStereoLayerFunctionLibrary::HideSplashScreen();
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("Game slot not found: %s"), *SlotName);
	}
}
// Fill out your copyright notice in the Description page of Project Settings.

#include "PaintingGridCard.h"
#include "Components/TextBlock.h"
#include "Components/Button.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/StereoLayerFunctionLibrary.h"

void UPaintingGridCard::SetPaintingName(FString NewPaintingName)
{
	PaintingName = NewPaintingName;
	SlotName->SetText(FText::FromString(PaintingName));
	CardButton->OnClicked.AddDynamic(this, &UPaintingGridCard::CardButtonClicked);
}

void UPaintingGridCard::CardButtonClicked()
{
	//UStereoLayerFunctionLibrary::ShowSplashScreen();

	UGameplayStatics::OpenLevel(GetWorld(), TEXT("TestMap"), true, "SlotName=" + PaintingName);
	UE_LOG(LogTemp,Warning,TEXT("options is : %s"),*PaintingName)

}

#include "PaintingGrid.h"
#include "Components/UniformGridPanel.h"
#include "Components/SizeBox.h"


void UPaintingGrid::AddPainting(int32 PaintingIndex, FString PaintingName)
{
	if (!PaintingGrid) return;
	
	UPaintingGridCard* NewWidget = CreateWidget<UPaintingGridCard>(GetWorld(), GridCardClass);
	if (!NewWidget) return;
	NewWidget->SetPaintingName(PaintingName);
	USizeBox* CardContainer = Cast<USizeBox>(PaintingGrid->GetChildAt(PaintingIndex));
	if (!CardContainer) return;

	CardContainer->AddChild(NewWidget);
}

#7

So could you walk us through your debugging process? What have you tried? I see some log messages in there, what do they show?


#8

in the UPaintingGridCard class when button was clicked log massage shows options which is ready for travel.and it shows savingslotname but the problem appears in the Gamemode in the init() method.it runs before clicking and because of that it doesn’t get any options.I’m wondering how it can be possible run init after clicking because in init method

this is called before actors’ PreInitializeComponents.


#9

How can the init be run before clicking? The gamemode should be loaded with the level which only happens after you click the card right?


#10

really?I thought GameMode runs before clicking,by the way I don’t know what happened in Gamemode() which GameMode cant Handle options. because of that my learning procedure stopped for two weeks I cant find solution.


#11

I suggest inserting lots of print statements to try and follow the execution flow. You can also attach the debugger and step through. It should be possible to pinpoint where the painting name is going missing.


#12

based on Game Flow Overview InitGame starts before BeginPlay and when it starts there is no slot name and slotname is empty if you see part of debugging it proves my words and last debugging massage is related to the PaintingGridCard after clicking :

LogTemp: Warning: SlotName in the init game : 
LogWorld: Bringing up level for play took: 0.004367
LogTemp: Warning: Game slot not found in Beginplay: 
LogSlate: New Slate User Created.  User Index 8, Is Virtual User: 1
LogSlate: Slate User Registered.  User Index 8, Is Virtual User: 1
PIE: Play in editor start time for /Game/Maps/UEDPIE_0_MainMenu 0.587
LogTexture: Display: Building textures: T_SteamVR_0 (BGRA8, 2048X2048)
LogTemp: Warning: options is in cardbuttonClicked : 54B2B02544EB7B0A015837A7E85E11E4```