- Home /
Unity Multiplayer (Mirror) - Problem in syncing game object's variables across all clients. [Trying to send command for object without authority]
Hi,
I am building a 3d virtual Auction house in Unity for my semester's project where multiple users can join the host server and interact with the action items in the game and increase their bids. The updated bid values should be synced across all the users. I am able to sync player's movements across the network by adding my "character controller" to the "player prefab" of the network manager. Users are also able to interact with the other game object to increase the item's bid locally. I am facing problems in syncing the updated bids of each auction item across the network for every clients.
I am adding each auction item to the "registered spawnable prefabs" list of the network manager.
Registered Spawnable Prefabs
This is the error I am getting
Trying to send command for object without authority. DataSync.CmdIncreaseBidUI
UnityEngine.Debug:LogWarning(Object)
Mirror.NetworkBehaviour:SendCommandInternal(Type, String, NetworkWriter, Int32, Boolean) (at Assets/Mirror/Runtime/NetworkBehaviour.cs:185)
DataSync:CmdIncreaseBidUI(Int32)
DataSync:Update() (at Assets/Scripts/DataSync.cs:38)
This is the script that I placed on my auction item. I am using the text mash pro game object to show the current bid of the auction item.
Game Scene
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class DataSync : NetworkBehaviour
{
// Start is called before the first frame update
[SyncVar]
public int num = 100;
public TMPro.TextMeshPro textObj;
void Start()
{
}
[Command]
public void CmdIncreaseBidUI(int num)
{
num += 100;
RpcIncreaseBidUI(num);
}
[ClientRpc]
public void RpcIncreaseBidUI(int num)
{
this.num = num;
GetComponent<TMPro.TextMeshProUGUI>().text = "Current Bid $" + num.ToString();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space"))
{
CmdIncreaseBidUI(num);
}
}
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Using networking solutions with AWS or Playfab servers with databases 1 Answer
How to test Unity's new networking layer in separate game instances? 0 Answers
Using Mirror Networking, is there a "Run Everywhere" attribute? 1 Answer
UNet | I'm having trouble assigning authority to game objects 0 Answers