1

I have an object what I use only in one scene, so I do not want to make it prefab. This object has network identity, and a script which is increasing a syncvar integer in the update method. When the game starts this object got disable because the server is not running. When I start hosting the server this object got enabled. Everything fine is this point but when a client is joining this object is still disabled in the client and not synchronized.

If I am right it is because the objects are not connected to each other. how and I solve it without making this object a prefab and just spawn it?

How can I spawn objects without a player prefab with authority on the server (it would be a singleton service object)?

1 Answer 1

3

NetworkIdentities have to be spawned. If it is already in your scene you can enforce it to be spawned by using

NetworkServer.SpawnObjects();

NetworkServer.SpawnObjects

Also you can spawn any prefab you defined in the NetworkManager. Look for the Registered Spawnable Prefabs Array. To spawn a registered prefab you can use

NetworkServer.Spawn();

NetworkServer.Spawn

For example spawn a registered prefab on the server using a Command:

[Command]
public void CmdSpawnGameObject()
{      
   var spawnObject = Instantiate(prefab, Vector3.zero, Quaternion.identity);
   NetworkServer.Spawn(spawnObject, connectionToClient);  
}

How can I spawn objects without a player prefab with authority on the server (it would be a singleton service object)?

You can't. You have to have a playerPrefab spawned and you have to have authority. But you can also hand over authority using

identity.AssignClientAuthority(conn);

Authority with Mirror

Not the answer you're looking for? Browse other questions tagged or ask your own question.