Search code examples
unity-game-enginetexturesrender

Save portion of view as material? (Unity3D)


How do I make a script that once a trigger is sent, it saves a portion of the view as a material that will STAY as a still picture as I walk around? (it doesn't change again.)

https://i.sstatic.net/WOyW8.jpg

Thanks, Quinn


Solution

  • There are, broadly, two options here, for what you're trying to achieve, but I think in this situation, taking a Screenshot is the easiest. You can find the Unity docs here.

    Once you have a Screenshot as a texture, you can display a Quad in front of the camera, and use the Texture2D for a material texture, You can even modify the UV values to make sure you only display that part of the screen you want.

    The other option would be to set the Output Texture of a Camera to be a Texture2D. The Unity docs for Output Texture are here. Again, you can then use this as your material texture to be displayed on a Quad in front of your game camera. You have options here; you may want to grab the output of your main camera for a frame, or you may want to use a second camera, that is enabled and renders the one frame on an event, then is disabled again until the next event. It's easy, but the slight drawback is that you need to make sure both cameras have the same view settings.