Invalid layer id

Hi, I have project that is made in one of previous versions of Unity and after I upgraded it I’m getting this error all the time:

Invalid layer id. Please use the unique id of the layer (which is not the same as its index in the list).

I have research about this but I can’t find any proper answer,

If needed I can provide more informations. Thanks for your time.

1 Like

As mentioned in the thread I linked, Unity at some point (looks like 5.2) changed this API point, so I’m guessing the value you’re passing as sortingLayerID is just being determined incorrectly. Depending on what data you have in the calling context, you might use something like SortingLayer.NameToID () to get the proper ID (but in that case you might as well just set SpriteRenderer.sortingLayerName). The ideal approach, if you’re using serialized data for sortingLayerID, is to serialize the integer ID for maximum performance, but e.g., expose the layer by name or in a drop-down in the inspector for easier editing (using e.g., PropertyDrawer).