The order of world and game instance initialization is different between a true standalone game (cooked game or an editor build with -game) and a Play In Editor game. Specifically, in Play in Editor it calls Init() on the GameInstance after it initializes the world in PostCreatePIEWorld.

This means that in true standalone games, UGameInstanceSubsystem classes like CommonUserSubsystem in Lyra always initialize before UWorldSubsystem classes like UUIExtensionSystem that are created in the startup map (it may create subsystems attached to an empty level, but those are deleted before gameplay starts). However in PIE startup it will create the world subsystems for the true startup map before it initializes the game instance. This is inconsistent behavior because for every other type of gameplay map load the game instance subsystem will already exist.

This issue is related to prior bugs like [Link Removed] which were fixed by moving the world initialization in PIE later during the startup process. However, the place it was moved to resolve that issue was slightly too early to resolve this issue. To be consistent between PIE and normal standalone startup, the simplest fix is to modify UGameInstance::InitializeForPlayInEditor and move the call to PostCreatePIEWorld after the Init() call. This is more consistent but may have side effects in games that depend on the old behavior.

Steps to Reproduce
  1. Sync and compile Lyra
  2. Add breakpoints (or UE_LOG lines) to UUIExtensionSubsystem::Initialize and UCommonUserSubsystem::Initialize
  3. Launch the lyra editor build with -game to create a standalone game equivalent to a cooked build
  4. Note that it calls UUIExtensionSubsystem::Initialize first on an empty world, followed by UCommonUserSubsystem::Initialize on the game instance, and then UUIExtensionSubsystem::Initialize a second time on the L_LyraFrontEnd world
  5. Close the game and launch the editor normally
  6. Open the L_LyraFrontEnd map using the toolbar map selector (or find it in content browser)
  7. Make sure Net Mode is set to Play Standalone and there is one player
  8. Start Play in editor

Expected behavior:

It should call CommonUserSubsystem::Initialize before UUIExtensionSubsystem::Initialize the same as it does for -Game

Broken behavior:

It first calls UUIExtensionSubsystem::Initialize on L_LyraFrontEnd, and then it calls UCommonUserSubsystem::Initialize. This order is different than the non-PIE order described above. It never initializes an empty map and the subsystems on the real map initialize too early in PIE

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-186247 in the post.

Login to Vote

ComponentUE - Gameplay
Affects Versions5.25.3
Target Fix5.3
Fix Commit25613936
CreatedMay 18, 2023
ResolvedSep 6, 2023
UpdatedDec 20, 2023
View Jira Issue