Custom Party Player Variables

Sooner or later you will probably want to add custom variables to party players instead of using the built-in Player Data feature. This guide will walk you through the process of creating custom replicated variables inside the party player state.

Setting Up Custom Player Variables

1. Creating the Party Player State class

First, create a new blueprint from the KronosPartyPlayerState class.

Now go to Project Settings -> Kronos Matchmaking and change the "Party Player State Class" to your custom blueprints.

2. Setting up Custom Variables

I'm going to create a new string variable simply called MyCustomString. Make sure that the variable's Replication is set to RepNotify! This will automatically create an OnRep function for us as well.

I'm also going to create a new event dispatcher for when the variable is changed. Since my variable is a string, I'm going to add a string param to the event dispatcher so that it can broadcast the new value.

3. Implementing the OnRep Function

Next we need to implement the OnRep function of the variable. This is called automatically by Unreal when the value of the replicated variable is changed. Here I simply want to call the event dispatcher created earlier.

circle-check

Modifying Custom Player Variables

Now that each party client has MyCustomString replicated in their player states, we just need a way to change the value of this variable. For this we are going to use the KronosPartyClient class, and I quickly want to explain why.

circle-exclamation

This means that the KronosPartyPlayerState should be used for data storage only, while the transition process from client to server should be done in the KronosPartyClient class instead.

1. Creating the Party Client class

First, create a new blueprint from the KronosPartyClient class.

Now go to Project Settings -> Kronos Matchmaking and change the "Party Client Class" to your custom blueprints.

2. Creating the Set Value Function

Create a new custom event called SetMyCustomString. Make sure that this event is set to "Run On Server" and Reliable! This will be the function to call when we want to change the value of the variable.

Now to actually change the value of MyCustomString, we simply need to get the player state of the party client, cast it to our custom blueprint, and set the string's value. Since the value is replicated it will now replicate down to the client and all other party members.

circle-check

Reading Custom Player Variables

In order to get the value of MyCustomString all we need to do is get a reference to the KronosPartyPlayerState, cast it to our custom blueprint, and get the current value. How we get the reference highly depends on the context. Here are some examples:

  • From party client: Use GetPlayerState function.

  • From party player actor: Use GetOwningPartyPlayerState function.

  • From party player widget: Use GetOwningPartyPlayerState function.

circle-info

Don't forget that we have also created the OnMyCustomStringChanged callback event, so you can assign an event to it and get notified when the value is changed!

Initializing Custom Player Variables

Use the built-in ServerInitPlayer and ClientInitPlayer functions of the KronosPartyClient. Please refer to Initializing Party Players section of the documentation for more details.

Last updated