[SyncVar(hook = "OnCurrentWeapon")]
public GameObject currentWeapon;
[Command]
public void Cmd_EquipWeapon(int itemID, int slotId)
{
GameObject newWeapon = Instantiate(somePrefab);
NetworkServer.SpawnWithClientAuthority(newWeapon, connectionToClient);
Rpc_EquipWeapon(newWeapon, slotId); //sending via RPC
currentWeapon = newWeapon; //setting the syncVar
}
[ClientRpc]
void Rpc_EquipWeapon(GameObject theWeapon, int slotId)
{
//This script on my objects hasAuthority to TRUE (Expected behaviour)
value.GetComponent<IToggleable>().toggle(gameObject);
}
void OnCurrentWeapon(GameObject value)
{
if (value)
{
//This script on my objects hasAuthority to FALSE(Unexpectedbehaviour)
value.GetComponent<IToggleable>().toggle(gameObject);
}
currentWeapon = value;
}
Hi, if I SpawnWithClientAuthority a Gameobject and immediatly Sync it to clients via Syncvar hook, it’s HasAuthority is false… I think it should be TRUE.
When I check for authority in the RPC called right after SpawnWithClientAuthority, which heppens AFTER OnCurrentWeapon, the HasAuthority value is TRUE.
Is this working as expected or is this a bug?
Thank you,
Jonathan
EDIT
Even more simple :
[Command]
public void Cmd_EquipWeapon(int itemID, int slotId)
{
//Spawn new one
GameObject newWeapon = Instantiate(ItemsList.instance.getItemById(itemID).gameObject);
NetworkServer.SpawnWithClientAuthority(newWeapon, connectionToClient);
}
On the client, in the Start() method, HasAuthority is false…