Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 banana111 · Jan 28, 2018 at 12:43 AM · savingcapturescreenshot

saving a screenshot to the recources folder

Hello, I am trying to take a screen cap. of my game and save it in a folder which I can later Access. How do I save a screen Capture with

 ScreenCapture.CaptureScreenshot("Screenshot.png");

and save it to the Resources folder or even the Application.persistentDataPath. I know this is a verry stupid and easy quastion but I can't seem to find a simple answer. Thanks for your help in advanced .

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

1 Reply

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

Answer by KittenSnipes · Jan 28, 2018 at 05:56 AM

@banana111

Well you should not be ashamed for asking for help. Here is a simple example script. Hope it helps and cheers mate.

 using UnityEngine;
 //System.IO;: You need this to find the files in your Directory
 using System.IO;
 
 public class Your Script Name Here: MonoBehaviour {
     //screenCaptureKey: Change this to any key you want. It is easily changeable in the editor
     public KeyCode screenCaptureKey = KeyCode.F2;
 
     //ScreenCapDirectory: If you want a 
     //specific directory do something like this: "C:\\Users\\YourUserNameGoesHere\\Documents\\"
     //Or if you want to use Application.persistentDataPath put it in the 
     //void Start() method and leave this string empty.
     public string ScreenCapDirectory = "C:\\Users\\YourUserNameGoesHere\\Documents\\";
 
     //The name of the screen capture taken. Put anything you want
     public string ScreenCapName = "CoolPic";
 
     //This will be what type of file your screen capture is. Another type besides png is jpg.
     public string fileType = ".png";
 
     //Private variables to get how many screenshots exist
     private int count;
     private int ScreenCaps;
 
     void Start()
     {
         //Set them both to 0 at start
         count = 0;
         ScreenCaps = 0;
 
         //This file path is C:\Users\YourUserNameHere\AppData\LocalLow\YourEnteredCompanyNameHere
         ScreenCapDirectory = Application.persistentDataPath;
     }
 
     void Update () {
         //ScreenCaps: Say we have 2 files with the same name as your ScreenCapName,
         //            Well then this would just tell us 2 of those files exist.
         //            Then we add that value to our ScreenCaps number to reference later.
         ScreenCaps = (FindScreenCaptures(ScreenCapDirectory, ScreenCapName));
 
         //If we press our capture key
         if (Input.GetKeyDown(screenCaptureKey))
         {
             //This is how you save the screenshot to a certain directory and a certain name
             //(ScreenCaps + 1): We reference this from above and use it for our picture name
             //                  So if we know 2 files exist we add 1 to our value so it is a new picture.
             ScreenCapture.CaptureScreenshot(ScreenCapDirectory + ScreenCapName + (ScreenCaps + 1) + fileType);
             Debug.Log("ScreenCapture Taken!");
             Debug.Log("ScreenCap Location: " + ScreenCapDirectory);
         }
     }
 
     //This gets all the existing files from the Directory (DirectoryPath)
     //with the FileName(FileName).
     int FindScreenCaptures(string DirectoryPath, string FileName)
     {
         //Set count to 0 at every run so we count up from 0 to 
         //how many files exist with the FileName entered
         count = 0;
 
         //This loops through the files in your entered Directory
         for (int i = 0; i < Directory.GetFiles(DirectoryPath).Length; i++)
         {
             //If any file has the same name as your picture
             if (Directory.GetFiles(DirectoryPath)[i].Contains(FileName))
             {
                 //Add 1 to the count because we need to know how many
                 //files with the same name exist
                 count += 1;
             }
         }
         //Once we know we return that amount
         return count;
     }
 }

Comment
Add comment · Show 5 · 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 banana111 · Jan 28, 2018 at 11:51 AM 0
Share

Thanksssss a lot!!! Your so nice. Is the Application.persistentDataPath a permenent directory? SO if I try to access it when the player turns the game on for the sacond time, will the png file still be there?

avatar image KittenSnipes banana111 · Jan 28, 2018 at 11:53 AM 1
Share

@banana111

The Application.persistentDataPath is a permanent path yes but the image will be saved over due to the name being the same. You can check to see if the image exists and if it does just add a 1 to it. I can help you with that if needed.

avatar image KittenSnipes KittenSnipes · Jan 28, 2018 at 12:25 PM 1
Share

@banana111

I fixed the script. Try it out and see if it works please. :D If it does make sure to mark this as correct. Cheers mate.

Show more comments

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

75 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

Related Questions

saving the game in position 1 Answer

PlayerPrefs Lmitations 2 Answers

Problem about reading and writing from text files 1 Answer

Where to find saves in the registry? 1 Answer

Working With GUI 1 Answer


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