How do I prevent UpdateCatchupPath from running on the Host (Server + Client) as the client? Currently it is called there by RPCUpdateCatchupPath.
Assistant
In Unity's Mirror networking, when you're dealing with a Host setup (which is both a server and a client in one instance), you might want to ensure that certain methods are only executed on clients that are not also the server. In this case, you want UpdateCatchupPath to not execute as a client method on the Host.
To achieve this, you can check if the current instance is the host by checking both isServer and isClient flags. If both flags are true, you're running as the host. You can then add an additional condition to prevent the execution of the method on the Host as a client.
Here's how you can modify the RPCUpdateCatchupPath method to prevent it from running on the Host (Server + Client) as the client:
csharp
[ClientRpc(channel = Channels.Unreliable)]
private void RPCUpdateCatchupPath(Vector3 startingPosition, List<Vector3> vectorPath, double time)
{
// This will check if the instance is not a Host (not both server and client)
if (!isServer || !isClient)
{
UpdateCatchupPath(startingPosition, vectorPath, time);
}
}
However, since you have a typo in your method names (UpdateCathupPath vs UpdateCatchupPath), make sure that you correct the typo first to maintain consistency and avoid confusion. The corrected method name should be UpdateCatchupPath.
After fixing the typo, your methods should look like this:
csharp
[Command(channel = Channels.Unreliable)]
private void UpdateClientPaths(Vector3 startingPosition, List<Vector3> vectorPath, double time)
{
RPCUpdateCatchupPath(startingPosition, vectorPath, time);
UpdateCatchupPath(startingPosition, vectorPath, time);
}
[ClientRpc(channel = Channels.Unreliable)]
private void RPCUpdateCatchupPath(Vector3 startingPosition, List<Vector3> vectorPath, double time)
{
if (!isServer || !isClient) // Don't run this on the Host as a client
{
UpdateCatchupPath(startingPosition, vectorPath, time);
}
}
private void UpdateCatchupPath(Vector3 startingPosition, List<Vector3> vectorPath, double time)
{
// Your existing implementation...
}
This change ensures that UpdateCatchupPath will not be called on the Host as a client, but it will still be called