-2

I want my game to save a png. Using the answer here I can do that, but how/where do I save them to a path relative to the game and not specific to my computer?

Is there a path similar to how PlayerPrefs are saved such that I don't need to know or specify where they are saved, but the OS and Unity know where to create them?

Ben Mora
  • 279
  • 3
  • 16

1 Answers1

1

You can try using one of the built in path strings provided by Unity (check the sample below) and generate a path that is relative to one of those locations.

Usage example

using System;
using System.IO;
using UnityEngine;

public class TestScript : MonoBehaviour
{
    private void Start()
    {
        string path = GetTemporaryImagePath();

        // Code to save an image at "path"
        // ...
    }

    private string GetTemporaryImagePath()
    {
        return Path.Combine(Application.temporaryCachePath, $"{Guid.NewGuid()}.png");
    }
}
Quickz
  • 1,626
  • 2
  • 11
  • 21
  • Thank you so much! I didn't know enough to know exactly what to ask, and this is exactly what I didn't know I needed! Thanks! – Ben Mora Jul 05 '21 at 23:33