Skip to main content

Chrome console throws error TypeError LayerMask.$clone is not a function

This error could be caused by the compound assignment syntax which can be incorrectly transpiled from C# to JavaScript.

images-medium

Possible solution:

  • Instead of using compound assignment syntax, assign the value explicitly.

For example, this line will not compile in Luna:

// compound assignment will not compile in Luna
character.LayerMask |= 1 << LayerMask.NameToLayer(GameManager.ENEMY);

Instead, assign the value as follows:

character.LayerMask = character.LayerMask |= 1 << LayerMask.NameToLayer(GameManager.ENEMY);