ScreenCapture.CaptureScreenshot is not working in 2017.1

Hi,
After updated to Unity 2017.1 my ScreenCapture.CaptureScreenshot code is not working properly. It generates screenshot of random window/panels, sometimes including the “game” window. The same code worked just fine in 5.6 (I know it was called Application.CaptureScreenshot prior to 2017.1)

Is anyone else having this issue? What is the work around?

TIA

Documentation says its been removed:

https://docs.unity3d.com/ScriptReference/Application.CaptureScreenshot.html

Just found out that, if you set your game view to “Free Aspect” then this problem is less likely to happen. But it is still not guaranteed.

private bool m_screenShotLock = false;

    private void LateUpdate()
    {
        if (Input.GetKeyDown(KeyCode.S) && !m_screenShotLock)
        {
            m_screenShotLock = true;
            StartCoroutine(TakeScreenShotCo());
        }
    }

    private IEnumerator TakeScreenShotCo()
    {
        yield return new WaitForEndOfFrame();

        var directory = new DirectoryInfo(Application.dataPath);
        var path = Path.Combine(directory.Parent.FullName, string.Format("Screenshot_{0}.png", DateTime.Now.ToString("yyyyMMdd_Hmmss")));
        Debug.Log("Taking screenshot to " + path);
        ScreenCapture.CaptureScreenshot(path);
        m_screenShotLock = false;
    }

This code worked for me - it seemed that using LateUpdate alone did not do the trick.
But using a Coroutine and waiting for end of frame worked finally.

I did not have the exactly same problem as every sceenshot turned out as black image for me, but I
hope that helps anyone.

For me, I needed to make sure to go to the package manager, select “Built-in packages” and then Make sure that Screen Capture and Image Conversion were both enabled.