Part 6 : Playercontroller

Back to main post

According to documentation : One PlayerController exists on each client per player on that machine. These are replicated between the server and the associated client, but are not replicated to other clients, resulting in the server having PlayerControllers for every player, but local clients having only the PlayerControllers for their local players. PlayerControllers exist while the client is connected, and are associated with Pawns, but are not destroyed and respawned like Pawns often are. They are well-suited to communicating information between clients and servers without replicating this information to other clients, such as the server telling the client to ping its minimap in response to a game event that only that player detects.

https://docs.unrealengine.com/en-US/API/Runtime/Engine/GameFramework/APlayerController/index.html

So it is better to use the playercontroller instead of the character for accessing client and server?

Step 1 : Create Playercontroller, create interface and create reference to Playercontroller.
Note: Actually I also created the gamemode (see Part 7). I set the new gamemode for my level. So also as step 1 als take a look at step 1 of part 7. 🙂

Create PlayerController and interface

Player Controller reference in interface
Connect interface to controller and build Ref function
Set your GameMode in your Level. Set Default Pawn Class and PlayerControllerClass.

Step 2 : Move blueprints from character to playercontroller

I am going to move the “Second video Part 5 extra changes” from the character to the player controller. This is just an exercise, I could argue that the best location for these Blueprints is actually the character.

So I moved the blueprints from the character to the playercontroller. I had to do some recompiling/ rebuilding. And I had to connect to Blueprints to the interface “Event Pickup Collected”. Also add the variable Healh which should be replicated.

PickupCollected in Interface
Blueprints in playercontroller part 1
Blueprints in playercontroller part 2

Actually the biggest change was in the BP_Pickup. On overlap, the character (pawn) is given. It is the playercontroller of the character that you need. This can by achieved by using the Get Controller function. Also the Pickup Collected interface function had to be added.

Blueprint in BP_Pickup

Video result step 1 en 2

Video step 1 and 2

After entering the name in the menu. Get the playerinfo from the gameinstance and store it in the playercontroller on both client and server.

Step 3 Make SetplayerInfo in interface playercontroller.

Setplayerinfo in interface
Blueprints in Playercontroller, Var PlayerInfo added (replicated)
Blueprint in widget MainMenu

Result in Dedicated Server

Result step 3
Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.