Setting renderer.sortingLayerID via code

Hi there,
I want to set the sortingLayerID of an objects renderer, via renderer.sortingLayerID = some_int; My understanding on how to get the int, is to use int layer = LayerMask.NameToLayer(“nameOfLayerIWant”);

My issue is that I am getting a return value of layer = -1. This despite having this particular layer, set in the ProjectSettings, see pics.

Any thoughts?
Thanks


Close! So close… LayerMask is for the 32 bitfield layers that Unity uses for lights, cameras, visibility.

I’m pretty sure what you want is this:

Unity has Layers, Tags, and SortingLayers… it’s super easy to get them crossed up, speaking from my own mixups.