Trying to use Graphics.DrawTexture() to modify my texture

I'm trying to build a texture at runtime by doing the following in C#:

  1. Create a GameObject
  2. Add a camera component to the GameObject
  3. Create a RenderTexture and assign it to camera.targetTexture
  4. Blit a background image into the RenderTexture
  5. Add a script to the GameObject (more on script below)
  6. Call camera.Render()

My script.OnRenderObject() does a Graphics.DrawTexture() to draw a texture into a small area of the render texture.

My script.OnPostRender() does the following:

  1. Texture2D.ReadPixels() to copy the RenderTexture into a new texture I will use later.
  2. Texture2D.Apply()

The result is that I see the background image from the Blit call, but the DrawTexture image never shows up. Does DrawTexture not work within a Camera.Render() call?

Some other possibilities that I've tried (unsuccessfully):

  • Tried WaitForEndOfFrame in case the DrawTexture calls were still queued up and hadn't executed before OnPostRender() gets called.
  • I'm outputting log messages in OnObjectRender, so I know it's getting in there.

Any ideas or better solutions to my problem? I would post code, but it's a bit long.


Well, I never found a proper solution for this, so I ended up having to use Graphics.Blit to create a scaled version of the 'decal' texture, and then manually copy and alpha-blend it into the destination texture using SetPixels.

It's a lot less elegant and I can't do arbritrary rotations, but it does the bare minimum functionality I need. (sigh)