Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

What is the proper method to store an arbitrary file in the Asset folder that is always availble?

Discussion in 'Scripting' started by PropositionOne, Aug 22, 2015.

  1. PropositionOne

    PropositionOne

    Joined:
    Jul 25, 2015
    Posts:
    13
    Is it Application.dataPath? I'm somewhat confused about what it says about a few platforms:

    • Web player: The absolute url to the player data file folder (without the actual data file name)
    • WebGL: The absolute url to the player data file folder (without the actual data file name)

    What is the "player data file folder?" That doesn't sound like a place where permanent readonly assets will be stored, so how do I ensure I can always access a path in the asset folder for read and write in Editor and for read-only in final build?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Throw it in the resources folder.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not possible, since there is no local file access in webplayer or WebGL apps. You can download files from the web only.

    --Eric
     
  4. PropositionOne

    PropositionOne

    Joined:
    Jul 25, 2015
    Posts:
    13
    Here's my specific problem - I want to have a standard System.Object class that automatically acquires a link to a specific ScriptableObject instance that will always exist as a singleton in my project folder. Is there no way to do this?
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    What BoredMormon said about Resources sounds like what you'd want, then, since any assets in Resources are always included in a build regardless of whether they are directly referenced or not. You wouldn't be able to load Unity objects as arbitrary external files anyway.

    --Eric
     
  6. PropositionOne

    PropositionOne

    Joined:
    Jul 25, 2015
    Posts:
    13
    I guess I was confused on the nature of "Resources" folder - It said something about them not downloading with the rest of the assets on webplayer.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  8. PropositionOne

    PropositionOne

    Joined:
    Jul 25, 2015
    Posts:
    13
    This is what is confusing me on that page: "Furthermore, you may even want to load assets from a separate file or URL to reduce initial download time or allow for interchangeable game content"
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The key word is interchangeable content. Is your asset going to be present in the build and always the same? Use resources. If you asset will not be present until runtime you will need something more sophisticated.
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's not talking about Resources, it's talking about asset bundles.

    --Eric