Error: a game object can only be in one layer. The layer needs to be in the range [0...31]

I got a error where it says: A game object can only be in one layer. The layer needs to be in the range [0…31]. Here is my code:

string remoteLayerName = "RemotePlayer";
[SerializeField]
string dontDrawLayerName = "DontDraw";
[SerializeField]
GameObject playerGraphics;

[SerializeField]
GameObject playerUIPrefab;

[HideInInspector]
public GameObject playerUIInstance;

void Start ()
{
	// Disable components that should only be
	// active on the player that we control
	if (!isLocalPlayer)
	{
		DisableComponents();
		AssignRemoteLayer();
	}
	else
	{

		// Disable player graphics for local player
		SetLayerRecursively(playerGraphics, LayerMask.NameToLayer(dontDrawLayerName));

		// Create PlayerUI
		playerUIInstance = Instantiate(playerUIPrefab);
		playerUIInstance.name = playerUIPrefab.name;
	}
	GetComponent<Player>().Setup();
}
void SetLayerRecursively (GameObject obj, int newLayer)
{
	obj.layer = newLayer;
	foreach (Transform child in obj.transform)
	{
		SetLayerRecursively(child.gameObject, newLayer);
	}
}

If anyone knows how to fix this i would want to know :slight_smile:

Did you check what valus is returned by

 LayerMask.NameToLayer(dontDrawLayerName)

?

Given the Documentation on this function the function returns -1 if the layer was not found.
Please check this as you probably just have a configuration issue or a typo in your layer.

They Also same error is found in my project. If you find these solution then kindly Guide me.Thanks a lot
@KashifAli