Set default level in c++

Create class NativeGameInstance derived from UGameInstance and override Init

#pragma once

#include "CoreMinimal.h"
#include "Engine/GameInstance.h"
#include "GameMapsSettings.h"
#include "NativeGameInstance.generated.h"

/**
 * 
 */
UCLASS()
class CARDGAME_API UNativeGameInstance : public UGameInstance
{
	GENERATED_BODY()
	
public:
	virtual void Init() override;
};

#include "NativeGameInstance.h"

void UNativeGameInstance::Init()
{
	Super::Init();

	UGameMapsSettings::SetGameDefaultMap(TEXT("/Game/NewMap2.NewMap2"));
}

*.Build.cs add EngineSettings module

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EngineSettings" });

ProjectSettings → Maps&Modes → Game Instance Class: NativeGameInstance

If any problem let me know. My discord Andrew Bindraw #9014

1 Like