So, as a Free user in 4 who moved onto Unity 5, I was happy that I could now use RenderTextures. They’re awesome, and I wanted to use one for a dynamic, draggable minimap. A dedicated camera renders the mini-map to a RenderTexture, which I can then re-use in various UI places… and so I did.
In the Editor, everything looks fine. Observe the minimap (looks like a heightmap on purpose) in the centre of the screen:
Works brilliantly!
However, much to my dismay, when I tried hitting CTRL+B and testing a build out, the same screen looks like this:
… which, naturally, is a bummer.
Am I doing something wrong? The RenderTexture gets assigned to a RawImage component, without a material (as I read on some other RenderTexture-related answer). Adding a material doesn’t help either, because a blank material with the Unity 5 Standard shader gives me a warning that the material hasn’t got “stencil properties”, whatever that is, and stops showing the map altogether.
RenderTextures do definitely work in a standalone personal edition build. That pink you see is normally an indicator of a shader error. Are you seeing any relevant messages in the output log?
I thought this also happened when a material’s iffy. Interesting, as I’m not using any custom shaders in relation to the RenderTexture or GUI (I didn’t know that was possible, to be honest… is it?), and the output log is completely fine, except for a trio of strange “Fallback handler could not load library …PROJECT_NAME_Data/Mono/libc”.
I think I’ll try to copy the relevant assets over to a new project and submit a bug report, as Meltdown recommended.
EDIT: I can’t reproduce the bug in the testing project. I investigated the shaders, as the minimap meshRenderer uses the Unlit/Texture one, but this didn’t help either (a few cubes in the testing project were successfully rendered using both the same shader, and the default one). I then decided to try changing the minimap’s shader to the standard one (basically omitting the Shader.Find() call to the aforementioned unlit shader), then built again… and le voilà, it worked… But I want to use the Unlit shader, damnit!
EDIT 2: I created a generic material using my desired shader, referenced it, and it works. Been working with Unity for over a year and a half, now, and I’m still a moron. (I am a programmer by heart, though, not a designer, so that’s my weak excuse for not knowing what I’m doing.)
Thanks for guiding me in the right direction, ThomasCreate. It appears that this is regular behaviour, and I’m just an idiot for not being aware of it.
The reason Shader.Find() works in the editor but not in the build is because shaders that aren’t being used in the scene are omitted in the build. Unity doesn’t know that a script will use a shader at run time. If you want to use the unlit shader without having to reference it in the scene directly, you can include it in the build in Project Settings → Graphics.
Thanks, I didn’t know that. I’ll do it, though, as I’ll use the same shader for other spawned objects too, and I’d rather not reference yet another something in an already-bulky script, especially a one-off thing in that particular place.