Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

CaptureScreenshot not working in 2018

Discussion in 'Scripting' started by WDudderz, Oct 2, 2018.

  1. WDudderz

    WDudderz

    Joined:
    Apr 6, 2013
    Posts:
    12
    I have a tool which captures a screenshot in the editor, I've used it for months and it doesn't seem to work after upgrading 2018.

    Code (CSharp):
    1. public static void Capture(int scale)
    2.     {
    3.         if (!Directory.Exists("Screenshots"))
    4.         {
    5.             Directory.CreateDirectory("Screenshots");
    6.         }
    7.         string path = "Screenshots/" + SceneManager.GetActiveScene().name + "_" + System.DateTime.Now.ToString("dd.MM.yyyy_HHmmss") + ".png";
    8.         ScreenCapture.CaptureScreenshot(path, scale);
    9.     }
    Weirdly this script worked just once since the upgrade. Has anything changed which might effect have broken it?

    Cheers for any help!
     
  2. nilsdr

    nilsdr

    Joined:
    Oct 24, 2017
    Posts:
    374
    what about it doesn't work
     
  3. WDudderz

    WDudderz

    Joined:
    Apr 6, 2013
    Posts:
    12
    Typically I have found the fix immediately it after posting. You have to have the Game view open for ScreenCapture.CaptureScreenshot to work.
    It doesn't mention that in the documentation, but maybe it's too obvious!