@ferdinand : The GetAllAssetsNew is a far more elegant solution for the problem I am trying to solve and I've rewritten the code so that it works now. We use Corona render and Redshift so it's a bonus that this works with pretty much all materials.
Thank you very much for the help, I will put your information about the layer shader in my database for future reference as I'm sure it will become helpful in another project!
Kind regards,
Joep