Why do UI elements cast a shadow in build but not in Unity editor?

I have a prefab with some text in it that now works thanks to @marcel :cactus: fix.

When I look in the editor, the text does not cast a shadow but in the build, it does. If I add an image to the prefab, the image does not cast a shadow in the editor but it too casts a shadow in the build.

Is there a way to disable this?

Original Post on Discord

by user 563549194137239552

add canvas data and disable ‘cast shadows’ - but you instantiate objects at runtime right?
image.png

yes

by user 563549194137239552

but there is a canvas in the prefab so i should be able to disable in the prefab?

by user 563549194137239552

Try - im not sure if the setting is applied currently when you add/remove objects to the canvas at runtime tho

I will try… I keep getting this though and it’s five minute re-import every time… i think it happens whenever i change my prefab … it looks like it think i also changed this prefab

by user 563549194137239552

I am going to create a copy of that prefab outside of the package cache to see if it helps

by user 563549194137239552

OK… can confo9irm that it works even in a prefab

by user 563549194137239552

I’m not changing/adding objects to the canvas at runtime though… i am adding the whole canvas with the prefab

by user 563549194137239552

Ok - and that works as expected?

Which Unity version and SRP are you on? I believe this is a known issue in earlier 2021.3 versions where URP tries to upgrade materials in immutable packages (URP bug). I thought it’s fixed by now

2021.3.3f1 with URP

by user 563549194137239552

copying to a non immutable prefix seems to have done the trick

by user 563549194137239552

I should probably update to the latest 2021.3 version

by user 563549194137239552

Yes please do, that’s an early 2021.3 and those were … problematic

I updated to 2021.3.17f1 and now everything is purple so now I get your Twitter joke

by user 563549194137239552

Reimportal all did the trick to fix it

by user 563549194137239552