Unity not respecting Layer values.

I’m working on porting a game made on Unity and some script keeps changing the layer of some objects to their original values every loop of the game. I don’t know which script is doing this and I don’t wanna find it.

I need to enforce some objects to some layer value, so I did something like gameObject.layer = xxx; inside the Update method.

Pausing the game and examining the inspector showed me that those gameObjects were being set to their default layer, so I changed the script execution order to execute my script last.

What surprised me is that now the inspector shows the layer equals to my value but still the objects don’t appear in the right camera! That is, if I enable the camera to see their original layer, the objects are displayed even though their layer values in the inspector are different.

To make sure that my script was being the last thing to execute I made it run in LateUpdate and even on OnPreCull.

How can I further examine what’s going on?

NGUI was changing the layers. UIPanel changes the layers of all its children, and NGUI was being confused by my script changing layers back.