Example,
I have an image saved in Assets/Sprite/image.png. That was created runtime with Application.CaptureScreenShot().
Now I want to delete it runtime with code. I don’t want to delete it from editor window. Just delete it, when user pressed the space button.
How can i do this ? Any solution ? or any alternatives ?
No.
It will not show anything. No errors & do not delete the file. If I put a debug line after AssetDataBade.DeleteAsset(), that line will be printed, but asset won’t we deleted.
My machine is iMac with Mac OS X 10.11.3 with Unity 5.3.4. Does that make any difference ?
Tried your code, But sometimes it shows both errors.
Then I put a button and calling those deleting part on click of button, but still it do not work. Though, If I capture screenshot, then minimize the Unity(or open any other window except Unity) & then go back to Unity, Unity imports new screenshot & then I click the button. It will work. But it simply do not work runtime.
Before posting on forum, I tried this method also. But it was not working with Application.CaptureScreenshot()
Now I create screenshot with Texture2D.ReadPixel() & then encode to PNG.
Now, I can delete it very easily with System.IO.File.Delete.But it is not working with Application.CaptureScreenshot().
The assetdatabase does not exist at runtime, it’s an editor construct for editor scripting. Then again, the assets folder also does not exist at runtime, so your question doesn’t make a lot of sense.
What are you trying to do? At runtime you just use regular System.IO methods.
Oh! @bhavinpanara22 Do you mean by “runtime”, you want want to delete from a build?
As @Kiwasi says, a lot of editor stuffs (everything within the UnityEditor namespace) are not available from build.
I am trying to take screenshot of a gameplay & use it for something & delete it runtime. So, it will not take more memory.
Any suggestions, how can I do this ?