Search Unity

Import a file at runtime....possible?

Discussion in 'General Discussion' started by tvance929, Feb 8, 2016.

  1. tvance929

    tvance929

    Joined:
    May 15, 2015
    Posts:
    14
    I'd like for my users to be able to import a file ( probably an xml file ) into the game that I can read and do something with.

    Is this even possible?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    Yes, put it into "Resources" folder.
     
    tvance929 likes this.
  3. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    Resources folder is not something that your users will be able to access after the game has been built, but it is the standard depot for files you use for the game.

    Alternatively, you can also load files at runtime from the StreamingAssets folder which is accessible directly from your game directory post-build. You'll find it in your Assets/ folder pre-build.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yes. Depending on your platform and contents there are a bunch of different ways to do things. StreamingAssets, asset bundles, and System.IO are all good places to start your search.
     
    landon912 and tvance929 like this.
  5. Teravisor

    Teravisor

    Joined:
    Dec 29, 2014
    Posts:
    654
    Why noone mentioned WWW? It can open file and you can get .bytes of it (it's not good for streaming bytes though - it'll load whole file before bytes are accessible).
     
    tvance929, McMayhem and Kiwasi like this.
  6. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    The easiest way I can see is to make it create a folder where the game is located. Then have it pretty much copy over to the folder, then make a list function read the contents of the folder and select which one.

    But that's what I'd do, may not be the best way for localized streaming.
     
    tvance929 likes this.
  7. tvance929

    tvance929

    Joined:
    May 15, 2015
    Posts:
    14
    n1warhead this sounds interesting... although my first thought is this wouldnt work on mobile devices....right?