Saad Khawaja Menu

Permalink:

  • Dominic

    Hi,
    This is exactly what I’m looking for but it’s not working for me. I’ve pasted the code into a new C# script and connected it to the camera in a scene. When I click ‘k’ it saved an image but it’s just a blank transparency. Am I missing a step?

    • admin

      Make sure your dimensions are correct. The code is tested to work.

      Replace these lines:
      public int resWidth = 2550;
      public int resHeight = 3300;

      with these just in case – and check the dimensions of the screenshot if they are correct.

      int resWidth = Screen.width*4;
      int resHeight = Screen.height*4;

  • Dominic

    Wow, quick reply. I’ve changed the code but I still get an image with a partially transparent grey colour. None of the game objects are captured. Do I need to make any setting at all or should it capture whatever the camera is looking at when the game is running?

  • admin

    Hi,
    I’ve added a downloadable package to this article. Spread the love – download and let me know if it works!

    Cheers.

  • Dominic

    What version of Unity do you have this working on? I’m using 4.5.0f6 and it’s not working in the game view or once built.

  • admin

    That is extremely strange. I’m supposing you downloaded the package and opened the example scene – then pressed the Take Screenshot button?
    I have it tested on Unity 4.5.0.6f and 4.3 as well without any issue.

    The example scene must work. Can you share the screenshot that it takes?

  • Dominic

  • Dominic

    I’ve tried it again on another computer and it still won’t capture the image correctly. Does anyone else have this problem?

  • Dominic

    I’ve been told that Render Texture requires Pro. Which I don’t have and that explains the issue.

  • Dominic

    Sorry to be a pain. I’m now uisng Pro and it takes the screenshot. But if there is a Texture on the Material it shows as semi transparent. Any idea why this is happening?

  • Ben

    The reason for the transparency issue is due to your material colour. If you inspect it you will see that it will have an alpha set to 0.5 that the Renderer does not use but this script does.
    Simpy change this to full alpha and it should fix the issue.

  • Sam

    Hello, good job making this script and making it more useful,

    however every image I take is cut off at least half, if not more.
    I tried harding coding the x and y res like you had it before but that did not work either.

    Any other suggestions?

  • Sam

    actually more importantly the image is stretched badly, I was able to get my model in view

  • nomadic

    1) ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame.
    UnityEngine.Texture2D:ReadPixels(Rect, Int32, Int32)
    Screenshot:LateUpdate() (at Assets/my/Screenshot.cs:27)

    2) DirectoryNotFoundException: Could not find a part of the path “/Users/NomadicWarrior/Documents/Unity Projects/AssetsFromAssetStore/Assets/screenshots/screen_1108x3160_2015-10-28_05-57-20.png”.
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:292)
    System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
    (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int)
    System.IO.File.Create (System.String path, Int32 bufferSize) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:135)
    System.IO.File.Create (System.String path) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:130)
    System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:594)
    Screenshot.LateUpdate () (at Assets/my/Screenshot.cs:33)

    And tons of more similar Errors. There is no any screenshots

  • nomadic

    is it possible to save screenshots in Desktop? But I still didn’t get any screenshots in project asset folders

  • nomadic

    Oops, sorry. I can see my screenshots. It has created a new folders in Unity Project folder 1) C/Users/default/Desktop/UnityScreenshots

  • sai

    But how to screenshots with batch mode?

  • Helda Bbt

    Peut ton récupérer les captures faire dans un groupe d’objets genre Texture2D []??

  • Thanks for leaving a comment, please keep it clean. HTML allowed is strong, code and a href.