Unity Mirror OnStartServer spawn GameObjects
Hi !
So i'm new with Networking and i'm trying to learn with Mirror.
I'm trying to do a simple thing but i'm failing, so i ask for help.
I need to spawn a gameobject when the server starts, i go this, in the client&server windows it works, but when an other player Joins, the player is spawned as normal, but the two spawned gameobjects by the server doesn't show on the new joined player, this is the code:
public override void OnStartServer()
{
GameObject spawnPointInstance = Instantiate(spawnPoint, spawnPoint.position, spawnPoint.rotation);
CmdspawnPointsExecutor(spawnPointInstance);
}
[Command]
void CmdspawnPointsExecutor(GameObject spawnPoint)
{
NetworkServer.Spawn(spawnPoint);
}
This is one of the tests i made... but i'm not able to sync this spawned gameobjects.
The spawnPoint prefab is registered on Network Manager.
I tried with ClientRPC but the problem is the same.
Thank you !
Answer by DatmosPro · Nov 04, 2020 at 01:48 PM
Just solved, i don't know why it didn't worked before but as this script is attached to a gameobject on the scene, there is no need to call the Command, as this gamosobject is on the server, so this is the solution:
public override void OnStartServer()
{
GameObject spawnPointInstance = Instantiate(spawnPoint, spawnPoint.position, spawnPoint.rotation);
CmdspawnPointsExecutor(spawnPointInstance);
NetworkServer.Spawn(spawnPoint);
}
Easy as that -.-