How to Save Screenshots From Your Game - Unity Tutorial #5

Поділитися
Вставка
  • Опубліковано 20 жов 2024

КОМЕНТАРІ • 84

  • @SassyPantsy
    @SassyPantsy 2 роки тому +3

    If anybody has any issues accessing NativeGallery from a script (i.e vsStudio or whatever doesn't recognize it and gives a red error line), transfer NativeGallery's folders to your script files.

  • @mikewigen8646
    @mikewigen8646 3 роки тому +2

    omg yes! Dude. I've been following 10 different tutorials and read thousands of forum posts and I always got soldi black screenshots, they never show my stuff but your tut worked for me. thank you.

  • @marcellyrangel5419
    @marcellyrangel5419 3 роки тому +8

    Man thank you so much for doing everything that I asked, you made me so happy you have no idea! You’re such a nice person, and your tutorials are 10/10 👌🏻😍

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому

      Thanks a lot ! And no problem, your ideas were good. Don't hesitate to ask if you want to see other things :)

  • @belajashark
    @belajashark Рік тому

    Thank you so much, I exactly need taking screenshots without UI elements!!!!

  • @qabashameed7136
    @qabashameed7136 2 роки тому +1

    Thank you so much for this video. It works from the first run
    I spent days for this solution and this is the only one that worked

  • @haroo315
    @haroo315 Рік тому +1

    Thank you so much!! I've been struggling with this problem and your video solved everything 😆 Have a great day! 👍

  • @akash_the_phenomenal
    @akash_the_phenomenal 3 роки тому +1

    You are a life saver, I got irritated from others video on screenshot and want some latest video.
    Will implement it in my game.
    Thank you.
    All the best , you will definitely grow so much.
    Edit : Bro please help, screenshot is not showing anywhere in my mobile... Where it is saved??

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому

      Thank you, if you use the Native Gallery package like I did after 6:43 the image should be saved into your gallery path so "On Android, your images/videos are saved at DCIM/album/filename. On iOS 14+, the image/video will be saved to the default Photos album (i.e. album parameter will be ignored). On earlier iOS versions, the image/video will be saved to the target album. Make sure that the filename parameter includes the file's extension, as well".
      If you use the PC code before 6:43 then it will be saved in your app's folder so you can only see it by exploring the files, not in your gallery.
      If you used Native Gallery and used the same code I did and made sure your file name is valid ( some characters may not be allowed and you need it to end with the right extension like .png ) and it did not work, you can try reading the github page for possible fixes or contact the devs, I didn't make the package so I can't help you if you get errors. github.com/yasirkula/UnityNativeGallery

  • @cloudbaseddev4913
    @cloudbaseddev4913 3 роки тому +2

    Really Helpful Bro!! Subscribed!

  • @hardworkerstudio
    @hardworkerstudio 2 місяці тому

    Thank you very much for the tutorial, I followed you because of this tutorial!
    So.. for the Android I have to enable Developer mode every time? and my customer need to do it too?
    and for the iOS users?

  • @28mukromka84
    @28mukromka84 17 днів тому

    i love you man, u just save my life, thank u

  • @seanburns6208
    @seanburns6208 3 роки тому +2

    Max great video, thank you very much. It's working great for me on PC but when I build to Android (Galaxy S7) the screenshot doesn't seem to work or else I just can't find it gallery. Any suggestions? Did you run into any similar issues at the start? Also, any tips on including a share button?

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому

      Hey, thanks a lot. When you built it on your phone, did you switch the code to using UnityNativeGallery ? After 6:43 I show a different code for mobile, using the PC code on mobile will not add it to the gallery. If you did and it doesn't work, then maybe try reading the github page for QnA and other information that may help you fix or contacting the UnityNativeGallery devs at github.com/yasirkula/UnityNativeGallery
      Since I didn't make it and it worked for me ( Huawei P20 ), I can't really help you with this :(
      For sharing I don't think it's worth taking time to make it yourself, as there are already things you can import and work with for free. With a quick search I found this that seems good, but you can probably find many others: forum.unity.com/threads/native-share-for-android-ios-open-source.519865/ ( "Native Share for Android & iOS" on asset store )

  • @sevemz3359
    @sevemz3359 3 роки тому +1

    Thank you, you made the process easier

  • @erbiis9961
    @erbiis9961 Рік тому

    hello, is the savemanager script in the empty gameobject affecting the screenshot saving process? i dont see it when i create the empty gameobject and when i go through with all the steps, the screenshot is not taken

  • @liviwilmore7337
    @liviwilmore7337 2 роки тому +1

    Great Tutorial!
    Seem to be falling at a very early hurdle though;
    When I add my GameObject with the script attached to my button, Under function TakeScreenshot isn't listed under my Screenshot script.
    My script for this looks just like yours;
    public void TakeScreenshot()
    {
    StartCoroutine("DoScreenshot");
    }
    Any ideas why this might be?
    My project is an AR project if you think that might effect anything at all?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Hmmm that is really strange. If you have a public void TakeScreenshot() in your script, when you drag your gameobject with your script in your button, the function should appear. Do you see any other functions of your script appear ? Are you sure you dragged the right one ? Did you save your file after adding the function so Unity can see it ? You can also try restarting your project.

  • @elirapendora2397
    @elirapendora2397 2 роки тому +1

    Uhmmm I have a question it works fine for me in Unity Thank you very much ! But I have a small problem when I build it and try to screenshot it doesn't work for some reason I dont need to save it I just need to pass the texture to the object it works in the compiler but when built it doesn't

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Hmmm that's very strange. I suggest you look on the plug-in GitHub page. They have a QnA where they explain how to fix common errors. I didn't make the plug-in so I couldn't tell you how to fix that, sorry.

  • @tabithaabbott5478
    @tabithaabbott5478 2 роки тому +1

    Hello Hello! Does this approach work for WebGL builds? Ive been stuck for a week.
    Edit: do any of the multiple approaches in the video work for webl builds? I’m trying to save screenshot from game on website on to users devices.

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      I haven't tried it sorry. You can check the library's GitHub in the description they probably say if it does.

  • @hirannair5041
    @hirannair5041 2 роки тому +1

    I'm getting this error: "ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame."

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Hmmm it seems like this could be due to when the code is ran. If it is ran in the middle or between frames, it could do that. Make sure you are yielding until the end of the frame like I did in the video at the top of the screenshot function. ( like this: docs.unity3d.com/ScriptReference/WaitForEndOfFrame.html ). This way, you can make sure the scene is done drawing before reading so you make sure everything is in the screenshot and that you don't get errors.
      If it doesn't work for some reason, try using the "OnPostRenderCallback" function like on this page: docs.unity3d.com/ScriptReference/Texture2D.ReadPixels.html

  • @Ekalaivan
    @Ekalaivan 3 роки тому +1

    Thanks man, this working great, is there anyway to use the same plugin to record videos?

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому +1

      Sorry I don't think this plugin is made for that. Recording gameplay is usually pretty tricky so you might not find a plugin directly for it :(

    • @Ekalaivan
      @Ekalaivan 3 роки тому

      @@MaxMakesGames exactly, got one plugin for recording video but it's deprecated from Android 9 it seems. I don't know why Google keep on reducing the controls. Stucking with another project for enabling mobile's flashlight for a AR session with Vuforia, where the Torch light working fine on Oreo devices but not working on latest Android Device.

  • @Yukisando
    @Yukisando 8 місяців тому

    Thanks bud! Cool plugin.

  • @Kerem_MertGakadatil
    @Kerem_MertGakadatil 2 роки тому

    Image I saved turns out to be yellowish in PC

  • @noorsalama8911
    @noorsalama8911 2 роки тому

    thanks for the tutorial , but where will these screenshots be located after taking a screenshot

  • @paolademichelis5082
    @paolademichelis5082 2 роки тому +1

    Thanks for the video tutorial, it's great! What about for WebGL build? How can I save screenshots directly from the web into my download folder?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Thanks ! I searched a bit and apparently the only way would be to use JavaScript to open a file browser and save at the selected location. Apparently unity allows you to add custom JavaScript for web builds so try looking into that but I've never done it so I can't tell you more sorry.

  • @graphiteji
    @graphiteji 2 роки тому +1

    I want to load the saved file in the same scene
    tell me how

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      You can just keep the texture2d you created when saving and then set it on a sprite in your scene with
      Rect rect = new Rect(0, 0, texture.width, texture.height);
      Vector2 pivot = new Vector2(0.5f, 0.5f)
      Sprite sprite = Sprite.Create(texture, rect, pivot);
      spriteobject.GetComponent().sprite = sprite; //replace with whatever sprite you want to change.

  • @1234yokee
    @1234yokee 2 роки тому +1

    Thank so much. You are my life saver . But i have a small problem. my screenshot image size is too small (284x568) . How to fix this sir? pls

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Thank you. If you used the same code as me, the screenshot size should be the size of the screen or window. When you create the texture, you can set the size. I put the screen width and height in the video, but you can put whatever you want. Just be aware that if you increase the texture size but use a smaller size in the ReadPixels, then it won't fill your texture. Maybe you are testing your game in a small 284x568 window ? Try making it full screen and see what it does 😁

  • @arnauz11
    @arnauz11 2 роки тому +1

    if i want to save screenshot in downloads, what i have to do? because if i upload my game, the players will not have Application datapath

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      When you build the game for release, the Application datapath will become the folder where your game exe data is I believe. So when the player run your game and take a screenshot, it will be saved where they have your game in their PC.
      However, after looking into it a bit, I'd recommend using Application.persistentDataPath instead to make sure the screenshots wont be deleted in updates and that the path doesn't change. On Windows, the files will be saved at "%userprofile%\AppData\Local\Packages\\LocalState". You can see more details here: docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
      If you really want the screenshots to be with the game files, then check out dataPath to see where it goes: docs.unity3d.com/ScriptReference/Application-dataPath.html

    • @arnauz11
      @arnauz11 2 роки тому

      @@MaxMakesGames but this way is very complicate for player because he/she doesn't know where screenshot is. If the screenshot saves in download files of pc, will be perfect.

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      @@arnauz11 All games save their screenshot in the game folders. Minecraft saves it in appdata for example. If you really want to save in the download folder, you'll have to use C# to get the path and use that path instead of Application Data path.

    • @arnauz11
      @arnauz11 2 роки тому

      @@MaxMakesGames thanks

  • @SassyPantsy
    @SassyPantsy 2 роки тому +2

    Btw you're the man

  • @兔兔-y4f
    @兔兔-y4f 2 роки тому +1

    ty i love u 😍

  • @adairvillalba1779
    @adairvillalba1779 2 роки тому

    como le puedo agragar una marca de agua a esta captura de pantalla, la imagen de agua que sea otra imagen.

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      I don't know exactly but I'd suggest looking into doing it with textures. For example, the screenshot is loaded as a texture before being saved so if you load your watermark as a texture too, you can probably put the watermark on the screenshot. Try something like this: answers.unity.com/questions/1561563/combine-2-textures-of-different-sizes-at-specific.html

  • @seymaple
    @seymaple Рік тому

    do you know a way to do the same things just in a webgl build? and save to downloads?

    • @MaxMakesGames
      @MaxMakesGames  Рік тому

      I doubt it's possible from unity because to save a file from the web you need to ask the browser to ( kinda ). Maybe you could if you edit the JavaScript created after building the webgl and code that part in JavaScript directly but idk how exactly.

  • @mesmes9424
    @mesmes9424 2 роки тому +1

    Can I assign the texture to the canvas image before saving it?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Yes ! I would suggest using Sprite.Create ( docs.unity3d.com/ScriptReference/Sprite.Create.html ) to create a sprite from your texture, so something like Sprite sprite = Sprite.Create(texture2d, new Rect(0, 0, size, size), new Vector2(size/2,size/2));
      Then set your canvas image sprite to that sprite using image.sprite = sprite;

    • @mesmes9424
      @mesmes9424 2 роки тому +1

      @@MaxMakesGames Thank you ! After trying that and not succeeded I figured it out that we need also to comment out the Destory(texture) function for it to work.

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      @@mesmes9424 Ahhhh yes it makes sense if you destroy the texture, it will not work. Thanks for telling your solution, maybe it can help others :)

    • @mesmes9424
      @mesmes9424 2 роки тому +1

      @@MaxMakesGames Thank you for this great tutorial!

  • @MegaCX
    @MegaCX 3 роки тому +1

    How can I save a screenshot in documents?

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому

      You need to check the path for documents on your PC and use that instead of the application dataPath. In my case, it is "C:\Users\Admin\Documents\" so I would use File.WriteAllBytes("C:\Users\Admin\Documents\ScreenShot.png", bytes) And ofc like I showed after you can add a timestamp so every screenshot has a different name.

  • @nixter361
    @nixter361 2 роки тому

    Great tutorial. Can we also send the screenshot to server ?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      Hmmm I guess once the file is saved on the PC/Phone then you can upload it to a server, but I've never done that. Maybe search "C# server file upload" or something like that.

  • @techlightdev
    @techlightdev 3 роки тому

    I can not save ScreenShot on my android device but pc is work. Can you help me ? thank you

    • @MaxMakesGames
      @MaxMakesGames  3 роки тому

      You need to use the native gallery plugin like I showed at the end. If it does not work, contact the devs on their GitHub. I didn't make it so I can't help you if you used the same code that worked for me but it doesn't for you, sorry...

  • @adairvillalba1779
    @adairvillalba1779 2 роки тому

    cual es la versión de Native Gallery para la versión de unity 2019.4.35f.

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      Try the latest version, it should work.

    • @adairvillalba1779
      @adairvillalba1779 2 роки тому

      @@MaxMakesGames no me funcionó, solo me funciona para las versiones superiores a 2019

  • @Abedalaziz_game_dev
    @Abedalaziz_game_dev 2 роки тому +1

    Love you

  • @noorsalama8911
    @noorsalama8911 2 роки тому

    when i added this to my button and i try it out on the phone it asks if its ok to give access to my photos and i said ok to screenshot but i dont seem to find the screenshot , how can i find it ?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      If you used NativeGallery.SaveImageToGallery, the screenshot should be saved in your phone's gallery. The GitHub page for the plugin says this:
      On Android, your images/videos are saved at DCIM/album/filename. On iOS 14+, the image/video will be saved to the default Photos album (i.e. album parameter will be ignored). On earlier iOS versions, the image/video will be saved to the target album.
      You can read more and check for possible fixes if it's not working for you here: github.com/yasirkula/UnityNativeGallery

    • @noorsalama8911
      @noorsalama8911 2 роки тому

      @@MaxMakesGames i did use native gallery , and when I click the camera button in the editor it says successfully screenshot Taken but when I have it on phone , it seems that it screenshots but I don’t find it when I go to my gallery ? i mean should I assign any name to my script or

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому

      @@noorsalama8911 Then it might be a problem with the plugin... I didn't make it so I can't really do anything about it. I suggest looking at their github I linked, they have a QnA and a bunch of infos. They also show different versions of the function you can try. If nothing works, maybe try contacting them. As you saw in the video it worked for me so I have no clue why it doesn't work for you... sorry :/

    • @noorsalama8911
      @noorsalama8911 2 роки тому

      @@MaxMakesGames by the way did you use the new or old input system for this ?

    • @MaxMakesGames
      @MaxMakesGames  2 роки тому +1

      @@noorsalama8911 I think I used the old one but it shouldn't matter as long as your code is being ran. You said it asked for permission so I'm guessing your code is being ran.

  • @farikhanniazi7042
    @farikhanniazi7042 2 роки тому

    Plz Share the script
    screen short

  • @shortStories197
    @shortStories197 Рік тому

    How to load those pictures in game

    • @MaxMakesGames
      @MaxMakesGames  Рік тому +1

      You can load a PNG file as bytes onto a Texture2D in Unity by using the LoadImage function of the Texture2D class. This function takes a byte array as an argument, which can be obtained from the PNG file. Here’s an example:
      string filePath = ... // The path to the PNG file
      byte[] imageBytes = File.ReadAllBytes(filePath);
      Texture2D texture = new Texture2D(1,1);
      texture.LoadImage(imageBytes);
      Once you have the Texture2D, you can display it on a canvas by creating a new RawImage object and setting its texture property to the Texture2D you created. Here’s an example:
      RawImage image = GetComponent();
      image.texture = texture;

  • @darkbatu
    @darkbatu 2 роки тому

    thank you so much!!!

  • @simpleguyissimple
    @simpleguyissimple Рік тому

    Does this also work on IOS?

    • @MaxMakesGames
      @MaxMakesGames  Рік тому +1

      The GitHub page says it does but I haven't tried it :)

    • @simpleguyissimple
      @simpleguyissimple Рік тому

      @@MaxMakesGames okay thanks, man! Great content btw!