Custom Render Texture not working in Player (PC). Works in Editor

In my game I’m simulating vision for my monster’s AI by rendering a lo-fi colour-coded version of the scene to a texture. I then use a custom render texture to summarise that data to a vertical ‘slot’ for analysis by the CPU.

(Don’t worry, there’s only one monster in the game XD)

All this works just fine in the editor. This is the debug view I have of the two textures, one above the other:

The red-ringed bit is the raw vision texture, the blue-ringed green stripe is the 1-pixel-wide summary texture stretched to the same width.

This is what I get in the player:

The top bit being fully green is correct: the monster is pressed up against a bright wall. However, the bottom bit being… not there (zero alpha, presumably) indicates that the custom render texture pass either isn’t happening or is going wrong somehow.

The custom render texture is set to ‘initialise’ to solid black (not happening) and then update in realtime with a period of 0 (every frame)

There’s nothing in the log apart from this (which might be a red herring because I’m not using Enlighten for anything and because the bit about releasing the render texture only seems to show up when I quit):

Setting up 4 worker threads for Enlighten.
Thread → id: 1114 → priority: 1
Thread → id: 30c0 → priority: 1
Thread → id: 2028 → priority: 1
Thread → id: 49b0 → priority: 1
Releasing render texture that is set to be RenderTexture.active!
(Filename: C:\buildslave\unity\build\Runtime/Graphics/RenderTexture.cpp Line: 911)

Not only is the texture not rendering in the debug view, the data pulled from it is blank, so my monster is blind.

I’m at a bit of a loss what to do other than stop using CustomRenderTexture and go for a horrible hacky Camera/Layer/Quad approach. Any suggestions?

So far I have tried:

Enabling/disabling double buffering on the texture
Ticking ‘keep shaders alive’ in the player
Making the shader a simple solid colour fill
Putting the texture on an object in the scene, not just a sprite
Adding an update zone to cover the entire texture
Changing the size of the texture to 32x32 instead of 1x32
Setting an update period other than 0
Changing the intialisation options
Changing from CGPROGRAM to HLSLPROGRAM
Giving the pass a name
Adding tags to disable ZWrite and ZTest and Alpha test
Setting RenderTexture.active back to null after reading pixels from the texture
Caching and restoring RenderTexture.active when I realised I probably shouldn’t be setting it to null
Adding the material, the source texture and the destination texture to Preloaded Assets


FYI I’ve ended up hacking this with a layer and camera and quad because it proved beyond my wit to persuade the built version of the game to execute the custom render texture.

1 Like