This character section is simply an example of how you might go about passing data to your own character. We are calling this later on from the component.
Open BP_ThirdPersonCharacter
On the Event Graph, create a new Custom Event
Create an event called SetupCharacterData with an input of type FN00dLobbyCharacterInfoDataExample.
Promote the input pin to a new variable
Since we are using data for this example character, this is data that will be set on your character and is representative of the data type that you might have for your characters
In the details of the variable FN00dLobbyCharacterInfoExample you just created, set it as RepNotify
Open OnRep_CharacterData
Add this script within.
Fill out the defaults of this class with the classes we care about, the PlayerController and the DefaultPawn
Make sure bUseSeamlessTravel is flagged.
In the components window, add BPC_Lobby
Override SpawnDefaultPawnFor
And call SpawnGameModePawnFor from the lobby component
Also override OnPostLogin and call OnPostGameLogin from the lobby component
Compile and save, we are done with this class
Same as last time, let's fill out the defaults of this class again, this time with the addition of the spectator along with the player controller and default pawn
Make sure bUseSeamlessTravel is flagged.
Add the component to the components window
On BeginPlay, call InitialiseLobby from the component and override OnPostLogin and OnLogout, calling the OnPostLobbyLogin and LobbyLogout respectively
We also need to override SpawnDefaultPawnFor and ChoosePlayerStart
Call SpawnLobbyPawnFor
Call ChooseLobbyStart
Compile and save, we are doing great!
NOTE: in the Class Settings of your component in the Lobby Game Mode, you have some options to change if you want to use different modes of spawning and visualising the character. We are leaving them the default for the example
Add the lobby component
Define BP_PlayerController in the defaults
Class Defaults of this class are just the defaults, no extra steps necessary
Compile and save, that's the game modes complete
Add the lobby component
Also make sure this component replicates
Pull off the lobby component and GetLobbyWidget, cast to WBP_Lobby and call ShowChatWidget. You will be creating your own later if you want, and you would cast to that instead.
Compile and save, the Player Controller is complete
IMPORTANT NOTE: If your project uses multiple controllers (i.e., menu controller, lobby controller, gameplay controller), you must define the component on each; the included examples only use a single controller for all the levels.
Add the lobby component
Also add a new CapsuleComponent and a child ArrowComponent
Name the CapsuleComponent CharacterPreview and the ArrowComponent FacingDirection
Capsule component transform
That's us here. Compile and save
Under the class defaults we want to turn off AddDefaultMovementBindings on this class
Well done, that's the classes all setup! Now let's move onto setting up our lobby component
For full control over our character spawns, we must now override several functions to build and assign the pawns the players have chosen. For this example we will be using data types, but you can also build the characters based on any classes you may have. See the example component included in the plugin for more script that will get that job done for you.
Open BPC_Lobby
Create a variable called CharacterData based on the struct FN00dLobbyCharacterInfoDataExample, make it an array type
These are the functions we will be overriding
Override them by hovering over the Functions category under the Override dropdown
In the overridden function. build this script
For both the data table functions, fill out DT_N00dLobbyCharacterData.
This is using the example data table. You are not limited to use this.
Handle this however you want. Show a widget on the controller, for example. We are simple making this player not spawn at any player start in this parent.
Grab the index of our Character Data and plug its Name into Character Name
Pull off GetPlayerPawnMap and call find, followed by UpdatePawnData
We don't care about the index here because the DefaultPawnClass is the class we will be using to build data on. The index is used if you want to spawn specific character classes.
Grab the CharacterData array and get its length, minus 1. And return.
Let's go ahead and call that function on the Third Person Character we created eariler. Remember: this is representative of your own character and you may do things differently here, however this is where we want to construct the data on your character class.
That's all the script we need!
Save and compile, have a coffee if need be, you deserve it!