Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 GoodGuyA · Jun 06, 2014 at 10:46 PM · updatepicture

Updating Taken Pictures in Game

Hey all! I am using the following code to create usable .png files in my resources folder which are being called to a texture inside of my game.

using UnityEngine; using System.Collections; using System.IO;

public class SnappitPictureTake : MonoBehaviour {

 private int count = 0;


 void Update()
 {
     if (Input.GetKeyDown("k"))
         StartCoroutine(ScreenshotEncode());


 }
 
 IEnumerator ScreenshotEncode()
 {
     // wait for graphics to render
     yield return new WaitForEndOfFrame();
     
     // create a texture to pass to encoding
     Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
     
     // put buffer into texture
     texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
     texture.Apply();
     
     // split the process up--ReadPixels() and the GetPixels() call inside of the encoder are both pretty heavy
     yield return 0;
     
     byte[] bytes = texture.EncodeToPNG();
     
     // save our test image (could also upload to WWW)
     File.WriteAllBytes(Application.dataPath + "/../Assets/Resources/testscreen-" + count + ".png", bytes);
     count++;
     
     // Added by Karl. - Tell unity to delete the texture, by default it seems to keep hold of it and memory crashes will occur after too many screenshots.
     DestroyObject( texture );
     
     Debug.Log( Application.dataPath + "/../Assets/Resources/testscreen-" + count + ".png" );
 }

}

The issue, however, is that these pictures are supposed to update in game over each other when a picture overwrites a previous one. They do eventually do such, but only if you exit the unity menu and return to the game, or otherwise restart the game.

Any way that I can force the game to call upon the newly updated file, rather than wait for a refresh? I'd like to allow the photos to be viewed in game and be the actual photos to be viewed, rather than otherwise.

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
0

Answer by unimechanic · Dec 03, 2014 at 02:38 PM

The description of the problem is pretty vague, but if you have the script you can modify it to fit your needs:

https://unity3d.com/learn/tutorials/modules/beginner/scripting

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

22 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

Related Questions

How do i delay function Update 3 Answers

Follow Script, Locking Y Axis 1 Answer

Update scene every 5 minutes 2 Answers

Is it possible to change builds structures? 2 Answers

[SOLVE] Target lock missile script - how to make it keep searching for new target 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