Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Dheinamar · Jul 17, 2019 at 12:59 PM · yieldscreenshotasyncasynchronousscreencapture

Take screenshot and use it as texture using ScreenCapture

I need to take screenshot and hold it in memory so later I can serialise it in save file with all the other information I need to save. We're using Unity 2019.3.0a8 and as documentation says for taking screenshots there is class ScreenCapture for which I wasn't able to find any information except for Unity Scripting API. So I have two questions.

First, as documentation says I need to wait till the end of frame rendering and the proper way of doing so is (taken from ScreenCapture.CaptureScreenshotAsTexture)

IEnumerator TakeScreenshot() { yield return new WaitForEndOfFrame(); var texture = ScreenCapture.CaptureScreenshotAsTexture(); // do something with texture // cleanup Object.Destroy(texture); }

However if I'm using yield return, I can't have neither return value for the method nor ref parameter thus I can't use the screenshot inside the method in which I call StartCoroutine(TakeScreenshot());. I was thinking of using async/await but it allows me to wait only for some amount of seconds and not exactly till the end of frame. How can I wait for end of frame rendering without using yield?

Second question here.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by kala-hari · Jul 17, 2019 at 06:53 PM

One way to solve the issue with returning values from Coroutines is passing a Callback to the Coroutine method.

The Callback can be called after the screenshot is taken, and receive the result as a Parameter.

For example:

  void HandleScreenshot()
  {
      StartCoroutine(TakeScreenshot((result) => {
          FurtherProcessing(result);
      });
  
  }
  
  IEnumerator TakeScreenShot(System.Action<ResultType> callback)
  {
      yield return new WaitForEndOfFrame();
      var result = new ResultType(ScreenCapture.CaptureScreenshotAsTexture());
      callback(result);
  }

Don't forget to destroy the texture aftwards.

Comment
Add comment · Show 2 · 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 Dheinamar · Jul 28, 2019 at 01:29 PM 0
Share

I've just added all further processing into TakeScreenshot. I just don't know why didn't I do this in first place. Anyway, thank you for the help.

avatar image kala-hari · Jul 29, 2019 at 07:42 AM 0
Share

Glad I could help :)

avatar image
0

Answer by WookieWookie · May 06 at 08:49 PM

I get this error that is a known bug but only has 2 upvotes:

Metal: GrabIntoRenderTexture mismatched grab pass: 80 / 70

Comment
Add comment · 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

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

114 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Asynchronously Load a Scene, then switch to it on function call Unity 5.3 1 Answer

Async/Await function hangs when caller has infinite loop 1 Answer

Asyncchronous image loading 2 Answers

How can I asynchronously load and save text files? 1 Answer

Making a forloop wait for previous code to finish before executing without a noticable delay? 0 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