playMaker

Author Topic: RenderTexture to Texture2D (code included!)  (Read 2781 times)

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
RenderTexture to Texture2D (code included!)
« on: August 12, 2016, 06:00:11 PM »
Hi,

I would like to request a RenderTexture to Texture2D action. It would basically do just that: read a RenderTexture object variable, and output its content to a Texture2D variable.

It's done like this:

Code: [Select]
//to read a RenderTexture, you have to set it as active temporarily
//so we save the current one to set it back to active when we're done
oldRenderTexture = RenderTexture.active;

//now we start; we set our RenderTexture as active
RenderTexture.active = myRenderTexture;

//we make our Texture2D read from the RenderTexture and put the whole data into the Texture2D
myTexture2D.ReadPixels(new Rect(0, 0, myRenderTexture.width, myRenderTexture.height), 0, 0);

//we apply it
myTexture2D.Apply();

//we set RenderTexture.active back to the original, because we're done
RenderTexture.active = oldRenderTexture

It should be noted that for this to work, first the target Texture2D variable height and width must be set to the same height and width as the RenderTexture we're converting from.

I'm just pretty bad at the moment at transforming this into an action. But the code is there and it works exactly like that.

Thanks a lot in advance, I really need this.
« Last Edit: August 13, 2016, 04:27:43 AM by joepalos »

joepalos

  • Playmaker Newbie
  • *
  • Posts: 28
Re: RenderTexture to Texture2D (code included!)
« Reply #1 on: August 17, 2016, 01:26:01 PM »
Well thanks for all the help & tips. I made it myself.

http://hutonggames.com/playmakerforum/index.php?topic=13401.0