I have been trying to make a functioning spawning system in a game I’m making, I’ve followed countless tutorials and read through pages of documentation and I still don’t understand why this isn’t working. Here is my code:
public void SpawnBulletLocalityCheck(Vector3 bulletPos, Quaternion bulletRot)
{
if(!isLocalPlayer)
{
return;
}
else if(isLocalPlayer)
{
spawnBullet(bulletPos, bulletRot);
}
}
[Command]
public void spawnBullet(Vector3 pos, Quaternion rot)
{
Debug.Log("object spawned locally");
GameObject b = Instantiate(Bullet, pos, rot);
NetworkServer.Spawn(b);
Debug.Log("object Spawned on server");
}
I have tried other variations of this code like:
[Command]
public void BulletSpawn(Vector3 Pos, Quaternion Rot)
{
Debug.Log("Bullet Spawned");
GameObject go = Instantiate(Bullet, Pos, Rot);
NetworkServer.Spawn(go);
}
Yet no matter how many times I remake it i get the same error, “NetworkServer is not active. Cannot spawn objects without an active server.” The script is derived from NetworkBehaviour and I have tried troubleshooting and found that the code works seamlessly for the Host, they spawn the object on the server and the client can see said object. Yet, for the client the server is “not active”. I made sure that the bullet prefab was in the Registered Spawnable Prefabs on the Network Manager and have even tried playing with the network identity. Does anybody have any idea why this is happening and any way I can fix it?