SlotName does not travel!

33_lp_vr2
virtual-reality-vr
light-painter

#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);
		

}


Solution: each Level has different GameMode() you need to set modified GameMode() in the both level (Menu and Drawing) and thanks Sam for his Soloution.


#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```

#13

But a new initgame gets called when we open a new level and that happens after we click the button.

Maybe I’m not clear on what the issue is or what you’re trying to achieve. Could you list the steps you are taking to reproduce the issue, the expected outcomes and the outcomes actually seen.


#14

Yes of course
first I put UE_LOG in the paintingGridCard to be sure options are not free and code is this:

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

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

that is ok and there is options and it

LogTemp: Warning: options is in cardbuttonClicked : 71B3250748825F5D73B1398FB71D7B72

now next step according to the tutorial it needs options get in the gamemode() now for the test I put another UE_LOG in the initgame()

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 in the init game : %s"), *SlotName);

}

and result is

LogTemp: Warning: SlotName in the init game : 
LogWorld: Bringing up level for play took: 0.004163
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.36
LogTexture: Display: Building textures: T_SteamVR_0 (BGRA8, 2048X2048)
LogTemp: Warning: options is in cardbuttonClicked : 71B3250748825F5D73B1398FB71D7B72

if you compare last line with end line you can see initgame() happens before clicking and it causes it doesn’t travel.

I wish it is clear for you


#15

It looks like your GameMode isn’t being loaded seeing as you don’t get the log after the click. Is the game mode set for the painting level?


#16

thank you,Exactly it solved I didn’t think in the other level gamemode can change.but there is a bit problem defaultPawn isn’t change in each level how can I solve it?for example in both level there is same UIVRPawn


#17

You need to set a different default pawn for the painting game mode. I suggest revising GameModes as it seems to be a source of confusion here.


closed #18

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.