Unity Mirror. Dont work Spawn on child objects

120 Views Asked by At

Faced a problem when working with Unity Mirror, namely when creating objects attached to the player. I'm trying to do something like taking up arms. And when I press the button, the weapon appears in the hands of the player only on the server side. On the client, it does not appear as a child object of the player at zero coordinates. How exactly can this be resolved? On the weapon prefab hangs NetworkIdentity.

public class EquipmentController : NetworkBehaviour, IEquipmentControllable
{
        [SerializeField] private GameObject testItemPrefab;
        [SerializeField] private Transform itemParentPoint;

        [Command]
        void CmdChangeWeapon()
        {
                // Instantiate new weapon on server-side
                GameObject newWeapon = Instantiate(testItemPrefab, itemParentPoint);
                NetworkServer.Spawn(newWeapon);

                // Set ownership and parent
                newWeapon.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);
                newWeapon.transform.SetParent(itemParentPoint);
        }

        public void HandleEquipInput()
        {
                if (!isLocalPlayer) return;
                CmdChangeWeapon();
        }
}

The weapon object does not have any scripts

Tried to do it according to the official instructions but the result was the same

0

There are 0 best solutions below