Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Built-In method to take a screenshot of the Inspector

Discussion in 'General Discussion' started by s0lt4r, Oct 4, 2018.

  1. s0lt4r

    s0lt4r

    Joined:
    Jun 9, 2015
    Posts:
    13
    Anyone know of a way to do this? I'm trying to document my set-up steps and having a full image of the inspector settings for objects would be useful. If you have any scripts or assets you know of, I'd appreciate it.
     
  2. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,408
    I think how the inspector handles rendering might make this really difficult. I notice that whenever I have Shadowplay on to record something, it jumps between each inspector window like they're all being rendered in their own little world
     
    angrypenguin likes this.
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Your regular windows snipping tool should work for screenshots.

    However if you just want to save inspector settings, it might be easier to just grab them out of the JSON.
     
  4. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,654
    Except where there's more than a window's worth of stuff to capture. A tool to handle that case nicely would be neat!
     
    Martin_H and Kiwasi like this.
  5. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    Edit: See my second post for a working solution.

    No, and that's my answer backed by at least an hour of working on a solution to do just that. While I was able to retrieve the info for the inspector window (it's marked internal but reflection can bypass that) I wasn't able to retrieve any of the pixels because all of the methods available work only on the game and scene views.

    I'm inclined to believe this is intentional as Unity 2018.2.9 replaces Application.CaptureScreenshot (which can capture the editor) with ScreenCapture.CaptureScreenshot (which can't capture the editor).

    Basically this is a job for a third party tool that supports automatically adjusting any captured screenshots. Like Photoshop.
     
    Last edited: Oct 5, 2018
  6. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,066
    photoshop.
     
  7. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,654
    That's really not my idea of "nicely". :p

    I wonder if there's something we could wrap a call to the GUI in so that it renders to a texture rather than the screen?
     
  8. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,066
    turn monitor 90º and max out resolution?

    It's such an edge case that you would have to screen shot an editor/inspector that is smaller than it's window, that I would just use photoshop to assemble multiple screenshots. It's really less than minute of work. Sure not super simple as it could be but in the grand scheme of things, it takes less time to assemble multiple shots than it does to google for a alternate solution. ;)
     
  9. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    Took a break and came back to it. Below is a functioning prototype. The Inspector has to have focus (that is you need to have clicked somewhere on the inspector before you try to capture a screenshot) otherwise ReadPixels will attempt to capture the contents of a completely different editor window.

    With the current path below the image will be saved into the base folder of your project.

    Code (csharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class CaptureInspector
    5. {
    6.     [MenuItem("Window/Capture Inspector _'")]
    7.     private static void Capture()
    8.     {
    9.         EditorWindow inspectorWindow = EditorWindow.GetWindow(typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"));
    10.         Texture2D inspectorTexture = new Texture2D((int)inspectorWindow.position.width, (int)inspectorWindow.position.height, TextureFormat.RGB24, false);
    11.  
    12.         inspectorTexture.ReadPixels(new Rect(0, 0, inspectorWindow.position.width, inspectorWindow.position.height), 0, 0);
    13.         inspectorTexture.Apply();
    14.  
    15.         byte[] bytes = inspectorTexture.EncodeToPNG();
    16.         System.IO.File.WriteAllBytes(Application.dataPath + "InspectorScreenshot.png", bytes);
    17.     }
    18. }
     
    CanisLupus and Kiwasi like this.
  10. zombiegorilla

    zombiegorilla

    Moderator

    Joined:
    May 8, 2012
    Posts:
    9,066
    Does it get the full height or just visible height?
     
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,937
    Only visible. I was just playing around with that to see what would happen.
     
  12. sbsmith

    sbsmith

    Joined:
    Feb 7, 2013
    Posts:
    129
    Possible update for Unity 2018.3.

    I was poking at this today and was having trouble because the tool triggering the capture was on a different window on a different screen and I couldn't consistently get access to the inspector's RenderTexture. This uses UnityEditorInternal.InternalEditorUtility.ReadScreenPixel instead of Texture2D.ReadPixels and works consistently for me.

    Code (CSharp):
    1. private static void CaptureWindowScreenshot()
    2. {
    3.     EditorWindow inspectorWindow = EditorWindow.GetWindow( typeof( Editor ).Assembly.GetType( "UnityEditor.InspectorWindow" ) );
    4.     inspectorWindow.Focus();
    5.  
    6.     EditorApplication.delayCall += () =>
    7.     {
    8.         int inspectorWidth = (int)inspectorWindow.position.width;
    9.         int inspectorHeight = (int)inspectorWindow.position.height;
    10.  
    11.         Color[] pixels = UnityEditorInternal.InternalEditorUtility.ReadScreenPixel( inspectorWindow.position.position, inspectorWidth, inspectorHeight );
    12.  
    13.         Texture2D inspectorTexture = new Texture2D( inspectorWidth, inspectorHeight, TextureFormat.RGB24, false );
    14.         inspectorTexture.SetPixels( pixels );
    15.  
    16.         byte[] bytes = inspectorTexture.EncodeToPNG();
    17.         System.IO.File.WriteAllBytes( Application.dataPath + "/InspectorScreenshot.png", bytes );
    18.     };
    19. }
     
    radiantboy likes this.
  13. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,637
    No, it only still grabs part of the window for me.
     
  14. popMark

    popMark

    Joined:
    Apr 14, 2013
    Posts:
    114

    Attached Files:

    Ryiah and Rodolfo-Rubens like this.
  15. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,824
    Seems like a safer and faster option is jut to create a prefabs.

    And specially nested prefabs are supported now.
     
  16. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,654
    That doesn't solve the same problem. This is for where you want to put images in instructions or manuals and references so on.