Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Jason-RT-Bond · Jul 21, 2015 at 08:13 PM · editorbuildwindowsmacscreenshot

Application.CaptureScreenshot() Fails on PC/Mac

I have an app with a screenshot button which calls Application.CaptureScreenshot(), with an oversize of 4. It works fine within the editor but in my builds no screenshot file is created. The app pauses while taking a screen (so I know the code is still called), but no file appears to be created anywhere that I can locate.

I've tried simply providing a filename itself (which in the editor causes the file to be created in the project root folder), and appending Application.persistentDataPath (which in the editor causes the file to be created in the same place as all other save data). In neither case does any file appear when running a build.

Unity 5.1.1, Windows and Mac.

Anyone have any ideas on this?

Comment
Add comment · Show 5
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 Paulius-Liekis · Jul 22, 2015 at 11:53 AM 0
Share

Do you get any errors in the log file? Are we talking about web or standalone build?

avatar image Jason-RT-Bond · Jul 22, 2015 at 02:16 PM 0
Share

Standalone builds for either $$anonymous$$ac OS or Windows.

I hadn't thought about the player logs, but I checked now and don't see any messages about it.

avatar image Jordi-Bonastre · Jul 23, 2015 at 08:37 AM 0
Share

Could you try to build your app with "Development build" option enabled?

I tried this script and works fine (I'm using $$anonymous$$ac):

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Answer_1011955 : $$anonymous$$onoBehaviour {
 
     static int numScreenshot = 1;
     public Text pathText = null;
 
     public void TakeScreenshot(){
         Application.CaptureScreenshot(Application.dataPath+"screenshot"+numScreenshot.ToString()+".png" , 4);
         pathText.text = "Screenshot saved into " + Application.dataPath+"screenshot"+numScreenshot.ToString()+".png";
         numScreenshot++;
     }
 }

avatar image Jason-RT-Bond · Jul 23, 2015 at 07:17 PM 0
Share

Hi Jordi & Paulius,

After lots of testing I've realised that I was mistaken about what was happening in Windows (just got mixed up) and the problem is centred around $$anonymous$$ac OSX.

For each platform I tried saving 3 ways: by appending Application.dataPath (i.e. Application.dataPath + "/" + "filename.png"), by appending Application.persistentDataPath, and with just the filename with no folder appended up front.

Here were my results...

Windows:

  • dataPath: goes to the data folder under the .exe — not an ideal place for a screenshot, but okay

  • persistentDataPath: goes into the persistent data folder as expected! (good)

  • no folder: goes to the data folder under the .exe

$$anonymous$$ac:

  • dataPath: puts the screen inside the .app package, which is indeed where the data is, although this is not a location users should ever have to look for screenshots

  • persistentDataPath: goes into a persistent data path, BUT this is a different persistent data path than the one used when running in Editor!

  • no folder: file cannot be found anywhere! (no messages in log)


So, in short, there are two issues here, both of them $$anonymous$$ac-specific:

  1. The value of Application.persistentDataPath changes between Editor mode and a stand alone build.

This seems unintentional. In my case (company: Crafted Reveries Limited, app name: Shu's Garden) Editor mode resolves the path as "Library/Application Support/Crafted Reveries Limited/Shu_s Garden/". However, the stand alone build resolves it as "Library/Application Support/unity.Crafted Reveries Limited.Shu's Garden/".

That last bit seems like a bug in Unity.

  1. When the full path isn't specified, the file doesn't go to a default location.

It seems to go nowhere.

avatar image oscartocino · Jun 01, 2016 at 09:57 PM 0
Share

Try using this;

Application.CaptureScreenshot(Path.Combine(Application.persistentDataPath, fileName));

Working in my Unity Editor 5.2.1

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jordi-Bonastre · Jul 24, 2015 at 08:35 AM

Hi Jason. I am running Unity 5.1.2p1 and if I use this code, Unity saves the screenshot on the project folder.

 Application.CaptureScreenshot("ScreenshotNEW.png" , 4);

PersistentDataPath is a directory path where data expected to be kept between runs can be stored http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

dataPath contains the path to the game data folder http://docs.unity3d.com/ScriptReference/Application-dataPath.html

Could you try CaptureScreenshot function only using the name of the screenshot and tell me which version of Unity are you running?

Comment
Add comment · Show 1 · 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 Jason-RT-Bond · Jul 24, 2015 at 02:34 PM 0
Share

It does that when running in Editor mode, yes. But as I said above, this isn't the behaviour in stand alone builds. On Windows, it is saved in the data folder in this case, and on $$anonymous$$ac I cannot locate the file anywhere.

avatar image
0

Answer by Aqibsadiq · Apr 12, 2016 at 04:44 AM

@Jordi Bonastre @Jason RT Bond Try This Guys Here is simple Code for capturing screen shot, and showing the captured image on screen This Code is For Andriod and IPhone.For PC Just Give the Image Path

  public RawImage image;
  void Start()
  {
        Photo();
        Invoke("GetPhoto",1f);
  }
  
  public void Photo()
      {
          Application.CaptureScreenshot(Variables.ImageName);
      }
  
  public void GetPhoto()
      {    
          #if !UNITY_EDITOR
          string url = Application.persistentDataPath +"/"+Variables.ImageName;
          var bytes = File.ReadAllBytes( url );
          Texture2D texture = new Texture2D( 73, 73 );
          texture.LoadImage( bytes );
          image.texture= texture ;
          #endif
      }
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

26 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

Related Questions

Models appear in Mac build but not in Windows built 0 Answers

Can't build/export my game to windows 2 1 Answer

Distribute terrain in zones 3 Answers

Can I build for iphone in a Windows PC? 3 Answers

How can I access an external file within the same folder as the built .exe? 2 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