- Home /
Host Can Spawn Objects on all clients screen while the client can only spawn objects on their screen. Client Cannot Spawn Objects On The Server
The host of the game I am making can spawn objects through the server that everyone in the game including the host can see. Yet when the client tries to spawn an object that object is only visible on the clients screen, even though the spawning function is the exact same for the two players. Here is the code:
public GameObject Bullet;
public GameObject Cube;
public NetworkIdentity netid;
[Command]
public void CmdSpawn(Vector3 Pos, string name, Quaternion Rot)
{
Debug.Log(name + " " + "spawned");
GameObject go = (GameObject)Instantiate(Resources.Load<GameObject>("bullet"), Pos, Rot);
NetworkServer.SpawnWithClientAuthority(go, netid.connectionToClient);
}
[Command]
public void BulletSpawn(Vector3 Pos, Quaternion Rot)
{
Debug.Log("Bullet Spawned");
GameObject go = Instantiate(Bullet, Pos, Rot);
NetworkServer.SpawnWithClientAuthority(go, netid.connectionToClient);
}
[Command]
public void CubeSpawn(Vector3 Pos, Quaternion Rot)
{
Debug.Log("Actual Cube Spawned");
GameObject go = Instantiate(Cube, Pos, Rot);
NetworkServer.SpawnWithClientAuthority(go, netid.connectionToClient);
}
I have tried checking and unchecking both the localplayerauthority and serveronly boxes on the network identity on every object to no avail. I do not know why this is happening... can somebody help?
Answer by MUG806 · Feb 20, 2021 at 11:04 PM
Not sure about the specifics of how this all works with the networking system you are using, but usually, in a networked game only the server can do such things. You probably need to have the client send a message to the server to tell it to spawn the object, and then have the server do it.
Maybe I am mistaken but isn't that what the NetworkServer.Spawn function is for? If not could you give some sort of example on how to send a message to the server?