Hello,
I’m developing a multiplayer FPS, with a weapon changing system similar to those in other known FPS games.
As such, I’m disabling and activating selected weapons with gameobject.SetActive(value)
on Command and ClientRPC:
[Command] private void CmdShowWeapon(int weaponIndex)
{
GameObject p = NetworkServer.FindLocalObject(netId);
Weapon[] spawnedWeapons = p.GetComponentsInChildren<Weapon>(includeInactive: true);
for (int i = 0; i < spawnedWeapons.Length; i++)
spawnedWeapons*.gameObject.SetActive(i == weaponIndex);*
activeWeapon = spawnedWeapons[weaponIndex].gameObject;
RpcShowWeapon(weaponIndex);
}
[ClientRpc] public void RpcShowWeapon(int weaponIndex)
{
GameObject p = ClientScene.FindLocalObject(netId);
Weapon[] spawnedWeapons = p.GetComponentsInChildren(includeInactive: true);
for (int i = 0; i < spawnedWeapons.Length; i++)
spawnedWeapons*.gameObject.SetActive(i == weaponIndex);*
}
While a new client is connecting, all inactive weapons on the host seem “unspawned” to the client, and thus when the host change weapons, the client cannot see them as they do not show in the hierarchy.
Is there something I’m doing wrong, and does there a way to overcome this problem.
I’ve searched on google and here for this type of problem and found nothing which is coherent.
Thank you.