heapcleaner

Fucking UE4 LoadMap

Aug 31st, 2019
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. What the fuck happens when we load a fucking map !?
  2. ===================================================
  3. by Heapcleaner (ipat.bogor at gmail dot com)
  4.  
  5. Context:
  6. * Single player game
  7. * Non seamless travel
  8. * Using the vanilla gameplay framework classes including AGameModeBase and AGameStateBase
  9.  
  10. Notes:
  11. * lines with prefix [c++] is an override-able function in c++
  12. * lines with prefix [bp] is override-able function/event in both c++ and blueprint
  13. * lines with format !! {Name} !! is a MatchState, it does nothing, just keep on reading...
  14. * spawning actor before world->bBegunPlay is true will NOT trigger actor->BeginPlay
  15.  
  16. --- pseudo code ---
  17.  
  18. Engine->LoadMap(URL):
  19.  
  20. do some preparation ...
  21.  
  22. initialize the world:
  23. broadcast WorldDelegates.OnPreWorldInitialization
  24. do initialization stuff like configuring NavigationSystem, AI system, avoidance system, and shits...
  25. broadcast WorldDelegates.OnPostWorldInitialization
  26. stream the juicy persistent level
  27. world->bInitialized = true
  28.  
  29. spawn GameMode
  30.  
  31. flush level streaming ...
  32.  
  33. intialize actors for play:
  34. [c++] GameMode->InitGame()
  35. for each actor in the world:
  36. [c++] actor->PreInitializeComponents()
  37. spawn GameState
  38. !! EnteringMap !!
  39. for each actor in the world:
  40. [c++] actor->InitializeComponents()
  41. [c++] actor->PostInitializeComponents()
  42.  
  43. for each player in local player list:
  44. [c++] GameMode->Login(player):
  45. spawn the appropriate player controller for the player at a cool spot,
  46. there are a lot of c++ override-able functions that determines which
  47. player controller class to use and the player pawn/character and shits...
  48. [bp] GameMode->PostLogin(playerController)
  49.  
  50. world->BeginPlay():
  51. [c++] GameMode->StartPlay():
  52. !! WaitingToStart !!
  53. ...
  54. !! In Progress !!
  55. [c++] GameState->HandleBeginPlay()
  56. for each actor in the world:
  57. actor->BeginPlay()
  58. world->bBegunPlay = true
  59. world->bMatchStarted = true
  60.  
  61. --- WHAT THE ACTUAL FUCK !? I'M A BLUEPRINT ONLY USER ---
  62.  
  63. Calm your tits for fucks sake! Yes, I know that there are not a lot of blueprint override-able shits in the pseudo code.
  64. But fret not mate, that's where AGameMode (instead of AGameModeBase) and AGameState (instead of AGameStateBase) comes in.
  65. Because you see, there's this sweet 'MatchState' system for both of them, this is the BP event in game mode:
  66.  
  67. (GameMode BP event) OnSetMatchState(FName MatchState)
  68.  
  69. Now look at the lines with !! {MatchState} !! format in the pseudo-code, each line means that the MatchState event is triggered at that point.
  70.  
  71. So if you want to do something before all actors begin play is triggered, you can do it in the "EnteringMap" or the "InProgress" match state.
  72.  
  73. e.g:
  74.  
  75. <just pretend this is a blueprint event graph>
  76. OnSetMatchState(FName MatchState)
  77. if (MathState == "EnteringMap")
  78. MyAnalyticInterface->Add("player enters my cool map")
  79. if (MatchState == "InProgress")
  80. MyCoolActor = SpawnActor(BP_MyCoolActor) // will not trigger MyCoolActor->BeginPlay, because the world hasn't begun playing
  81.  
  82. --- Delayed start ? ---
  83.  
  84. There's a bDelayedStart property in AGameMode that you can set to True to make the game mode waits for you to start the game manually using GameMode->StartMatch(), which means, the BeginPlay triggering is now in your very own hand.
  85.  
  86. This is commonly used in multiplayer game to wait for other people to login before starting the game, but you can also use it in single player game to, let's say, streams additional levels / assets before starting the game and then fading the screen in, or whatever the fuck you want.
  87.  
  88. --- Other MatchStates ---
  89.  
  90. EnteringMap : We are entering this map, actors are not yet ticking
  91. WaitingToStart : Actors are ticking, but the match has not yet started
  92. InProgress : Normal gameplay is occurring. Specific games will have their own state machine inside this state
  93. WaitingPostMatch : Match has ended so we aren't accepting new players, but actors are still ticking
  94. LeavingMap : We are transitioning out of the map to another location
  95. Aborted : Match has failed due to network issues or other problems, cannot continue
Advertisement
Add Comment
Please, Sign In to add comment