- Home /
Only host client is able to spawn objects
Working on a small fps game project and been trying for forever to get something to work but without success. whenever player shoots his weapons, it should spawn a muzzle flash, a line to the target he hit, a decal and bullet impact effect. here's how it's setup in the Hierarchy:
FpsPlayer has a Network Identity, Transform and a ObjectSpawner Script
[Command]
public void Cmd_SpawnObject(GameObject toSpawn)
{
NetworkServer.Spawn(toSpawn);
}
This is so that it's the root object handles spawning it, the code for the gun is on the akm object under WeaponHolder and doesn't have a network identity.
and this is how I spawn an object:
go = GameObject.Instantiate(woodParticle, hitPoint, Quaternion.FromToRotation(Vector3.up, hitUpDir)) as GameObject;
((ObjectSpawner)transform.root.GetComponent(typeof(ObjectSpawner))).Cmd_SpawnObject(go);
I've also setup the prefabs on the player and network manager:
but when build and run, the host client is the only one who's able to spawn objects, when he shoots it spawns the muzzle flash, line, decal and bullet impact on the other client, but when the client shoots, only he sees it and the host sees nothing. same if I start 2 clients and one host, only host is able to spawn objects.
Your answer
Follow this Question
Related Questions
IS it possible to have delayed player spawning after server connection? (UNet) 1 Answer
NetworkSpawn.Spawn() on all clients EXCEPT calling client 0 Answers
UNET Bug with NetworkHash128 and Saving Prefabs 0 Answers
Server authoritative spawning bug? 1 Answer
UNET 5.2: How do you use NetworkServer.SpawnWithClientAuthority()? 1 Answer