Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Shatcore · Oct 18, 2012 at 07:20 PM · screenshotreadpixels

ReadPixels is capturing GUI, how to get a screencap without GUI

So I am trying to take a screenshot and then have it display in the top corner in a GUI texture, the 1st person character is basically supposed to be taking a photo with a camera then having that shot displayed in the corner gui.

I have the code working but the screenshot that goes to the gui texture actually contains the gui texture in it (or the previous photo) How do I avoid capturing the gui?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by phodges · Oct 18, 2012 at 08:03 PM

How about rendering the view to a texture, using a camera that contains no GUI?

EDIT: Added a simple RenderTexture demo

I'll add a couple of code snippets to demonstrate something along these lines using RenderTextures. Firstly, some setup information:

  • Two cameras in the scene: one for your regular view and another to take snapshots.

  • The snapshot camera should be placed wherever the viewpoint for these photographs is expected to be

  • The snapshot camera should have irrelevant items (such as GUILayer and AudioListener) removed and the Snapshot component added

  • Something needs to prompt the snapshots to be taken. I've provided a "Snapper" for this to support the logic: attach that to whichever object you want it on and assign its 'Snapshot' property correctly.

  • Pressing the 'S' key will cause a snapshot to be taken and then rendered in the OnGUI call. It could equally well be blitted using GL methods if that works better for you, but this seems more relevant to your question.

    // Snapshot.cs

    using UnityEngine; using System.Collections;

    [RequireComponent(typeof(Camera))]
    public class Snapshot : MonoBehaviour {

          public delegate void SnapshotEvent(Texture r);
     
            public int texWidth = 256;
            public int texHeight = 256;
     
            RenderTexture _renderTexture;
            SnapshotEvent OnSnapshotReady;
            bool _stop;
     
         // Use this for initialization
         void Start () {
              RenderTexture rt = new RenderTexture(texWidth,texHeight,24,RenderTextureFormat.ARGB32,RenderTextureReadWrite.Default);
              _renderTexture = rt;
              camera.targetTexture = rt;
              camera.enabled = false;
         }
     
         void Update() {
             if (_stop) {
                  camera.enabled = false;
             }
         }
     
         void OnPostRender() {
              _stop = true;
              if (null != OnSnapshotReady){
                  OnSnapshotReady(_renderTexture);
              }
         }
     
         public void TakeSnapshot(SnapshotEvent cb) {
                OnSnapshotReady = cb; 
                camera.enabled = true;
                _stop = false;
         }
     }
     
     
     // Snapper.cs
     
     using UnityEngine;
     using System.Collections;
     
     public class Snapper : MonoBehaviour {
     
            public Snapshot snapshot = null;
            Texture _snap = null;
     
         // Update is called once per frame
         void Update () {
             if (null != snapshot && Input.GetKeyDown(KeyCode.S)){
                snapshot.TakeSnapshot(OnSnapshotReady);
             }
         }
     
         void OnSnapshotReady(Texture rt){
              _snap = rt;
         }
     
         void OnGUI() {
              if (null != _snap){
                  GUILayout.Label("Snapshot ready");
             Rect r = new Rect(10f,10f,256f,256f);
             GUI.DrawTexture(r,_snap);
              }else{
             GUILayout.Label("No snapshot available");
              }
         }
     }
     
    
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Shatcore · Oct 19, 2012 at 06:27 AM 0
Share

Do you $$anonymous$$d explaining how I specify which camera I want to capture pixels?

avatar image alonsoGarrote · Sep 13, 2014 at 06:02 PM 0
Share

Does this work on Unity free? I believe it doesnt, as it uses RenderTexture, right?.

avatar image Piyush_Pandey · Mar 14, 2016 at 05:49 AM 0
Share

Thats a superb Idea bro. I was searching for something like a different operation than read per pixel. U rock.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture2D readPixels: How to only read a section of the camera view? 0 Answers

What's wrong with my screenshot function? 1 Answer

How can I make a RGBA32 PNG screenshot? 0 Answers

Texture2d.readPixels not working with iOS 6 3 Answers

Is there any way to execute ReadPixels (for capturing a screenshot) but on a camera that is currently not displaying anything on screen? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges