How to reference the client that sent the command

Hi folks,

Wondering if you can help? In summary i am building a FPS style prototype and I am attempting to implement a system where for example, player A launches projectile, it hits player B and player B takes damages and player A awarded a point. My projectile is instantiated with a CoherenceSync component. To reference the client that launched the projectile, I followed the below advice (https://docs.coherence.io/coherence-sdk-for-unity/networking-state-changes/commands).

Alternatively, if you want to know which Client sent the command, you can add CoherenceSync sender as the first argument of the command, and the correct value will be automatically filled in by the SDK.

Simply put it would look like this:

Sending the command on collision:

enemyCoherenceSync.SendCommand<PlayerHealth>(nameof(PlayerHealth.OnDamage), MessageTarget.AuthorityOnly);

Receive command:

/// <summary>
/// Records the damage taken
/// </summary>
[Command]
public void OnDamage(CoherenceSync sender)
{
    // Handle damage
}

However, I’m getting the below error (which makes perfect sense really), but unsure if I have the prescribed implementation correct or if I’ve got confused?

Error:

09:21:28.414 (coherence) CoherenceSync: Unable to send command ‘PlayerHealth.OnDamage’ to ‘[network] PlayerObject(Clone)’: command PlayerHealth.OnDamage() was not found. Check the command’s name and parameters, or Bake again

Note: I do have the method checked in the Coherence Sync config

SDK 1.0
Unity: 2022.3.4.f1

A broader questions would be, what would be the best practice, architecturally to implement that game behaviour that I mentioned?

Many thanks in advance!

Hey Ben, I’m asking the SDK team for clarification, I did some tests myself and I could use that technique. If it works, we definitely need to clarify the docs.
Will let you know.

1 Like

Hi Ben, I got an answer from the engine team. With that paragraph, you stumbled into a bit of legacy method that was removed a while ago. I am amending the docs to remove it, and adding a paragraph to explain how to do it in a different way.

This is what I have added, which should explain it somehow:

Identifying which Client sent a command

While commands by default carry no information on who sent them in order to optimise traffic, you can create commands that include a Client ID as one of the parameters. Then, on the receiving end, compare that value with a list of connected Clients.

You can create your own implementation for these IDs or, more simply, use coherence’s built-in Client Connections feature.

Is it clear? You should see it soon in the docs too.

1 Like

Hi Ciro, many thanks for check with the team and yes - this makes perfect sense. I’ll proceed by passing Client ID as you mention. Thanks again!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.