Mirror - attribute assigned to server, but not client.
First off, take the title with a grain of salt, it might be the wrong way round, this is really confusing.
I have a player death script in multiplayer (Mirror.) The problem is that while the clients can kill the server, the server can not kill the clients. I don't know how client v client works. The death script works by:
When a player is spawned, it gives it client authoirty and sets it's death component's "creator" game object to itself. When the plane detects that it's been shot, it checks for client authority and if it has it it tells the creator to spawn a copy of itself then destroys itself and it's derivatives. However, the die step is failing when it calls the creator to copy itself, and some debugging as shown that is is because it doesn't have the creator set. I then put logging in when it first creates the player, and sure enough it has a debug of "set creator" printed right after - so it evidently hasn't failed. I have verified that it can actually access the game object by logging it - it always shown UnityEngine.gameObject, not null.
Here's some relevant code: ``` [Command] public void CmdSpawnMyUnit() { //running on the server GameObject go = Instantiate(playerUnitPrefab);
//now it exists serverside, propagate over network to all clients
//spawn
NetworkServer.Spawn(go);
Debug.Log("Spawned");
//assign client authority
go.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);
Debug.Log("Assigned connection to client");
Debug.Log("# " + this.gameObject.ToString());
go.GetComponent<PlaneDeath>().creator = this.gameObject;
Debug.Log("Set creator");
}```
Death script:
```
void Die()
{
if (hasAuthority == false)
{
Debug.Log("Not dying because I don't have authority");
return;
}
DoDieNextFrame = false;
Debug.Log("Dying");
creator.GetComponent<PlayerConnectionObject>().CmdSpawnMyUnit();
Debug.Log("Destroying");
Destroy(controller);
Destroy(this.gameObject);
}
public void Update()
{
if (creator == null)
{
Debug.LogWarning("Creator is null");
}
externalAuthority = hasAuthority;
if (DoDieNextFrame)
{
Die();
}
if (Input.GetKeyDown(KeyCode.D))
{
DoDieNextFrame = true;
}
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.tag == "Bullet")
{
Debug.Log("Hit by bullet");
DoDieNextFrame = true;
}
}
} ```