#but the player only spawns on the host
1 messages · Page 1 of 1 (latest)
[ServerRpc(RequireOwnership = false)]
public void SetupPlayerServerRpc(int _selectedPlayerID)
{
MyDebugger.myDebugger.Log("Setup Player Server Rpc");
GameObject playerClone;
MyDebugger.myDebugger.Log($"Prefab List " + plrefablist);
for (int i = 0; i < plrefablist.PrefabList.Count; i++)
{
if (i == _selectedPlayerID)
{
playerClone = Instantiate(plrefablist.PrefabList[i].Prefab);
NetworkObject playerNetObj;
playerNetObj = playerClone.GetComponent<NetworkObject>();
playerNetObj.Spawn();
MyDebugger.myDebugger.Log($"Prefab Name " + plrefablist.PrefabList[i].Prefab);
}
}
}
this spawns the player on the host and i can move the player but if i try and sawn the client player it only spawns on the host side and the host controls both the host and client player. nothing happens on the client side.
Spawn() should create an object on the client as well.
You'll need to check your movement code so that only the local client is moving the player. the object will need a client network transform if your movement is client authoratative
shouldn't IsOwner handle that?
It should. depends on where you are checking it
Player Script:
why dose it look like its doing something twice?
I think OnNetworkSpawn() runs on the host server and the host client. So on the host it ends up running twice
any suggestions?
just something like if(IsServer) return;
brb, family time
Nope. I'm working on netcode for entities at the moment
It still dosnt work but what are your thoghts on this?
public override void OnNetworkSpawn()
{
MyDebugger.myDebugger.Log("Setup Player Server Rpc");
if (IsServer)
{
MyDebugger.myDebugger.Log("On Network Spawn - Is Server");
//return;
}
if (IsClient) {
MyDebugger.myDebugger.Log("On Network Spawn - Is Client");
}
if (IsHost) {
MyDebugger.myDebugger.Log("On Network Spawn - Is Host");
}
MyDebugger.myDebugger.Log($"Prefab List " + plrefablist);
for (int i = 0; i < plrefablist.PrefabList.Count; i++)
{
if (i == selectedPlayerID)
{
playerClone = Instantiate(plrefablist.PrefabList[i].Prefab);
playerClones.Add(playerClone);
MyDebugger.myDebugger.Log($"Prefab Name " + plrefablist.PrefabList[i].Prefab);
}
}
SetupPlayerServerRpc();
}
[ServerRpc(RequireOwnership = false)]
private void SetupPlayerServerRpc()
{
MyDebugger.myDebugger.Log($"Setup PlayerServer Rpc");
foreach (GameObject playerClone in playerClones)
{
NetworkObject playerNetObj = playerClone.GetComponent<NetworkObject>();
playerNetObj.Spawn();
//playerNetObjRef.TryGet(out NetworkObject playerNetObj);
}
}
As long as player clones is being set on the server. But at that point you don't really need the serverRPC. It should already be running on the server there. Playerclone.Spawn() should work there
Sorry to get a little off topic for a sec
I tried to add Multiplayer Tools from the package manager but it gave me a small error