How to Display Other Players

In this tutorial, you will learn how to display other players using Coala's Player Replication feature.

Requirements

    • Your project and map are setup according to the Installation page

    • In your Content Browser, Plugin and Engine content are not hidden

    • Your map is configured to use your Coala API Key

Setup

In your Content Browser, navigate to "ThoughtfishCoalaPlugin Content/Blueprints/PlayerReplication".

Open the "BP_Coala_PlayerRep_Handler_Example" Blueprint inside the PlayerReplication folder.

Its Blueprint Graph shows an example on how to configure Coala's Player Replication Subsystem to display other players.

Depending on how much control you want, you can either derive a new Blueprint from the example handler and change what you need, or do this configuration yourself, in both C++ code or Blueprint.

To do this, refer to the following sections and the example handler itself.

(If you are using C++, see Epic's documentation of Subsystems. The Player Replication Subsystem is a UWorldSubsystem)

Using the Example Handler as a Base for Your Own

If the only thing you want is to display the movements of other players, this section is for you.

Create a new Blueprint in your project and select the "BP_Coala_PlayerRep_Handler_Example" Blueprint as its base type.

Open the new Blueprint to edit it.

In the Details Panel to the right, you can select the type of Actor that is spawned for each player Coala receives as well as the Configuration Asset that contains the settings that you want to use.

(For an explanation of the Configuration Asset's settings and how to create another Configuration Asset, refer to this page)

To the left, next to the 'Functions' section, you can override parts of the example handler Blueprint to fit your needs by hovering over it and clicking 'override'.

If you want to use the Player Replication feature in shipping builds or on mobile, overriding the Get Local Player Id function is mandatory.

To do this, click on the Get Local Player Id function that appears once you press override. This will create and open an override for this function.

Here, you have to replace the "Parent: Get Local Player Id" node with custom code so that the functions returns a Local Player Id that is unique over your userbase.

(For instance a hash of a unique login name or similar)

That's it!

Once you drag and drop an instance of this custom Blueprint into your map, other players should be displayed around you.

The following sections explain how to do more customization.

Executing Work on Player Update, Addition, and Removal

In addition to spawning and removing players automatically, Coala's Player Replication feature enables you to perform additional actions each time a player

is Updated, Added, or Removed.

This can be useful if you are providing your own player blueprint for remote players by specifying it as class to spawn. For instance, if you want those actors to move across the map on each update.

To do this, open your subtype of "BP_Coala_PlayerRep_Handler_Example" that we created in the previous steps. Again, click on the override button to display possible function overrides.

This time, we will take a look at the "On New Player Added", "On Player Removed", and "On Update Player" events.

All of them pass along their player actor, which is guaranteed to be of the class you specified in the "Player Class to Spawn" variable of your handler Blueprint, you only have to cast it to this class to call its functions.

In addition, the events also pass 'Player Data'.

Player Data consists of the id and the payload this player set to Coala's Player Replication system on his own device,

which can be done using the "Set Local Player Payload" and "Set Local Player Id" functions.

(Keep in mind that if you use our example handler as a base, the id for the local player is automatically set to the id you output in the "Get Local Player Id" override of your custom handler)

The "On Update Player" event is special in the way that you should only override it if you want to use a remote player class that is not derived from the "BP_Coala_DefaultRemotePlayer" Blueprint.

It is intended as a hook to call into your own movement code, and therefore also passes the New World Position parameter, which is the new position the player should be moved to.

How to Change the Actor Spawned as Remote Player

If you only want to replace the mesh and animations of the other players without changing the way they move or adding other features to them, there is a way to do so!

As we did with your custom handler earlier, create a new Blueprint in your project, but this time, select "BP_Coala_DefaultRemotePlayer" as its parent type in the Parent Picker.

Once you open the new Blueprint and Select its SkeletalMesh component, you can choose a different mesh to be displayed.

Next, you have to chose new idle and movement animations for this skeletal mesh. You also need to specify how 'fast' your movement animation is (in Unreal Units moved per second) so that Coala knows what speed to play your animation at.

And finally, open your custom Player Replication handler to set your new player Blueprint as the one to be used when spawning players.