Skip to content

Crash in AModularExperienceGameMode::InitGameState() due to wrong class assignment #4

@DavidWyand

Description

@DavidWyand

While setting up a new project with all of your modular gameplay plugins, there is a consistent crash within AModularExperienceGameMode::InitGameState() while trying to set up a new AModularExperienceGameMode based game mode blueprint. And because of this crash you can never make changes to the game mode blueprint, nor actually play in editor if you use AModularExperienceGameMode as the default game mode.

The crash occurs within this code:

	// Listen for the experience load to complete.
	// @todo Ensure there is a default ExperienceComponent shipped.
	// Right now, if the project GameMode doesn't have a ExperienceComponent, this will crash.
	UModularExperienceComponent* ExperienceComponent = GameState->FindComponentByClass<UModularExperienceComponent>();
	check(ExperienceComponent);

Looking at the GameState member, it is using the AModularGameStateBase class which doesn't have the experience component on it. This game state class is set within the AModularGameModeBase constructor.

The solution to this crash is to set the correct game state class within the AModularExperienceGameMode constructor:

AModularExperienceGameMode::AModularExperienceGameMode(const FObjectInitializer& ObjectInitializer)
{
	// DAW: If we're using a Modular Experience Game Mode then we also need to use a Modular Experience Game State
	GameStateClass = AModularExperienceGameState::StaticClass();
}

This change allows for a AModularExperienceGameMode based blueprint to now be loaded up into the editor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions