Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What the fuck happens when we load a fucking map !?
- ===================================================
- by Heapcleaner (ipat.bogor at gmail dot com)
- Context:
- * Single player game
- * Non seamless travel
- * Using the vanilla gameplay framework classes including AGameModeBase and AGameStateBase
- Notes:
- * lines with prefix [c++] is an override-able function in c++
- * lines with prefix [bp] is override-able function/event in both c++ and blueprint
- * lines with format !! {Name} !! is a MatchState, it does nothing, just keep on reading...
- * spawning actor before world->bBegunPlay is true will NOT trigger actor->BeginPlay
- --- pseudo code ---
- Engine->LoadMap(URL):
- do some preparation ...
- initialize the world:
- broadcast WorldDelegates.OnPreWorldInitialization
- do initialization stuff like configuring NavigationSystem, AI system, avoidance system, and shits...
- broadcast WorldDelegates.OnPostWorldInitialization
- stream the juicy persistent level
- world->bInitialized = true
- spawn GameMode
- flush level streaming ...
- intialize actors for play:
- [c++] GameMode->InitGame()
- for each actor in the world:
- [c++] actor->PreInitializeComponents()
- spawn GameState
- !! EnteringMap !!
- for each actor in the world:
- [c++] actor->InitializeComponents()
- [c++] actor->PostInitializeComponents()
- for each player in local player list:
- [c++] GameMode->Login(player):
- spawn the appropriate player controller for the player at a cool spot,
- there are a lot of c++ override-able functions that determines which
- player controller class to use and the player pawn/character and shits...
- [bp] GameMode->PostLogin(playerController)
- world->BeginPlay():
- [c++] GameMode->StartPlay():
- !! WaitingToStart !!
- ...
- !! In Progress !!
- [c++] GameState->HandleBeginPlay()
- for each actor in the world:
- actor->BeginPlay()
- world->bBegunPlay = true
- world->bMatchStarted = true
- --- WHAT THE ACTUAL FUCK !? I'M A BLUEPRINT ONLY USER ---
- Calm your tits for fucks sake! Yes, I know that there are not a lot of blueprint override-able shits in the pseudo code.
- But fret not mate, that's where AGameMode (instead of AGameModeBase) and AGameState (instead of AGameStateBase) comes in.
- Because you see, there's this sweet 'MatchState' system for both of them, this is the BP event in game mode:
- (GameMode BP event) OnSetMatchState(FName MatchState)
- Now look at the lines with !! {MatchState} !! format in the pseudo-code, each line means that the MatchState event is triggered at that point.
- 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.
- e.g:
- <just pretend this is a blueprint event graph>
- OnSetMatchState(FName MatchState)
- if (MathState == "EnteringMap")
- MyAnalyticInterface->Add("player enters my cool map")
- if (MatchState == "InProgress")
- MyCoolActor = SpawnActor(BP_MyCoolActor) // will not trigger MyCoolActor->BeginPlay, because the world hasn't begun playing
- --- Delayed start ? ---
- 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.
- 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.
- --- Other MatchStates ---
- EnteringMap : We are entering this map, actors are not yet ticking
- WaitingToStart : Actors are ticking, but the match has not yet started
- InProgress : Normal gameplay is occurring. Specific games will have their own state machine inside this state
- WaitingPostMatch : Match has ended so we aren't accepting new players, but actors are still ticking
- LeavingMap : We are transitioning out of the map to another location
- Aborted : Match has failed due to network issues or other problems, cannot continue
Advertisement
Add Comment
Please, Sign In to add comment