Problem with Layer

I follow a tutorial on youtube to create your multiplayer games and then for some time there is this error that appears I do not know where the problem comes from.

Link video:

the error in question:

A game object can only be in one layer. The layer needs to be in the range [0…31]
UnityEngine.StackTraceUtility:ExtractStackTrace ()
Util:SetLayerRecursively (UnityEngine.GameObject,int) (at Assets/Scripts/Util.cs:7)
Util:SetLayerRecursively (UnityEngine.GameObject,int) (at Assets/Scripts/Util.cs:11)
Util:SetLayerRecursively (UnityEngine.GameObject,int) (at Assets/Scripts/Util.cs:11)
Util:SetLayerRecursively (UnityEngine.GameObject,int) (at Assets/Scripts/Util.cs:11)
WeaponManager:EquipWeapon (PlayerWeapon) (at Assets/Scripts/WeaponManager.cs:49)
WeaponManager:Start () (at Assets/Scripts/WeaponManager.cs:20)

PlayerSetup:

using UnityEngine;
using Mirror;

[RequireComponent(typeof(Player))]
[RequireComponent(typeof(PlayerController))]
public class PlayerSetup : NetworkBehaviour
{
    [SerializeField]
    Behaviour[] composentsToDisable;

    [SerializeField]
    private string remoteLayerName = "RemotePlayer";

    [SerializeField]
    private string dontDrawnLayerName = "DontDraw";

    [SerializeField]
    private GameObject playerGraphics;

    [SerializeField]
    private GameObject playerUIPrefab;
 
    [HideInInspector]
    public GameObject playerUIInstance;


    private void Start()
    {
        if(!isLocalPlayer)
        {
            DisableComponents();
            AssignRemoteLayer();
        }
        else
        {


            Util.SetLayerRecursively(playerGraphics, LayerMask.NameToLayer(dontDrawnLayerName));

            playerUIInstance = Instantiate(playerUIPrefab);

            PlayerUI ui = playerUIInstance.GetComponent<PlayerUI>();
            if(ui == null)
            {
                Debug.LogError("Pas de component Player UI sur playerUIIinstance");
            }
            else
            {
                ui.SetController(GetComponent<PlayerController>());
            }

            GetComponent<Player>().Setup();
        }

 
    }

    public override void OnStartClient()
    {
        base.OnStartClient();

        string netId = GetComponent<NetworkIdentity>().netId.ToString();
        Player player = GetComponent<Player>();

        GameManager.RegisterPlayer(netId, player);
    }

    private void AssignRemoteLayer()
    {
        gameObject.layer = LayerMask.NameToLayer(remoteLayerName);
    }

    private void DisableComponents()
    {
        for (int i = 0; i < composentsToDisable.Length; i++)
        {
            composentsToDisable[i].enabled =false;
        }
    }

    private void OnDisable()
    {
        Destroy(playerUIInstance);
        if(isLocalPlayer)
        {
            GameManager.instance.SetSceneCameraActive(true);
        }

        GameManager.UnregisterPlayer(transform.name);
    }
}

8462270–1123619–GameManager.cs (1.22 KB)
8462270–1123622–PlayerSetup.cs (2.12 KB)
8462270–1123625–PlayerWeapon.cs (253 Bytes)
8462270–1123628–Util.cs (306 Bytes)
8462270–1123631–WeaponManager.cs (1.23 KB)

It would be useful to include the error, we can’t see it from here :slight_smile:

a yes sorry my bad

Looks like a Unity error, not netcode related.
Check out the Unity manual on layers :slight_smile:

ok thanks

ok i searched but i didn’t find anything good can you help me it’s my first time with unity