Changing GameMode when loading new sublevel

Hello,

I am having issues having my game load a different gamemode when loading a new sublevel. I looked at as much documentations and tutorials as I could however I haven’t been able to find an answer.

I have created a new gamemode the following way

UCLASS()
class TESTGAME_API ABkInvadersGameMode : public AGameMode
{
	GENERATED_BODY()

		virtual void Tick(float DeltaSeconds) override;
public:

	ABkInvadersGameMode(const class FObjectInitializer& PCIP);
	
	UPROPERTY(EditDefaultsOnly, BluePrintReadWrite, Category = "Game Rules")
	int32 numEnemies;
};

All the cpp does is the following

ABkInvadersGameMode::ABkInvadersGameMode(const class FObjectInitializer& PCIP)
	:Super(PCIP)
{
	// default numEnemies
	numEnemies = 1;
}

void ABkInvadersGameMode::Tick(float DeltaSeconds)
{
	int i = 0;
	i++;

}

After doing this I opened one of my sublevels that I load via a blueprint using load stream level

and set my gamemode level override to my newly created gamemode

46809-gamemodesetting.png

However when i set a breakpoint in my gamemode, the constructor gets called as soon as the game starts, not when the gamemode is loaded and the Tick function never gets called.

I’ve tried looking as hard as I could and i am wondering: Did I setup something wrong? (probably)
does GameMode override not work with sublevels and or streaming?
Should I be doing this differently?

Thanks for the help! :slight_smile:

You have to use OpenLevel. Otherwise you are loading the level and merging with the existing level (you can’t have 2 gamemodes).

More info about level streaming here https://wiki.unrealengine.com/Blueprint_Manual_Level_Streaming

If you would like to change game mode with LoadStreamLevel you have to do it manually.

P.S. You forgot Super::Tick(DeltaSeconds);

Thanks!! :slight_smile:

How can I change the gamemode manually?

I too need to know how can I change the game mode manually??

Me too! I also need to know how to change the gamemode manually. Do I simply spawn a gamemode blueprint or something?