x


Is it o.k to save custom per-project .asset files in /Library?

Just wondering if this is an "o.k" thing to do and will not mess with the Unity project?

Are there any issues with doing this?

I wanted to use it to store per-project default settings for an AssetPostprocessor class I'm making. i.e:

[ System.Serializable ]
public class TextureAtlasImportSettings : ScriptableObject {
/// data goes here
public static TextureAtlasImportSettings GetDefaultTextureAtlasImportSettings()
{
    string libraryPath = System.IO.Path.GetDirectoryName( Application.dataPath )
                                                                 + "/Library/";
    string settingsPath = libraryPath+"DefaultTextureAtlasImportSettings.asset";

    TextureAtlasImportSettings settings = (TextureAtlasImportSettings)
         AssetDatabase.LoadAssetAtPath( 
          settingsPath,
          typeof(TextureAtlasImportSettings) 
         );

    if ( settings == null ) {
       settings = CreateInstance<TextureAtlasImportSettings>();
       settings.name = "DefaultTextureAtlasImportSettings";
       AssetDatabase.CreateAsset( settings,settingsPath );
    }

    return settings;
}
}
more ▼

asked Oct 03 '11 at 03:44 PM

DanKripac gravatar image

DanKripac
1 1 1 1

O.k so I've now tried my own code out (as I should have done before hand) and Unity prints an error and throws an Exception using the /Library path i.e: Couldn't create asset file! UnityException: Creating asset at path /path/to/game/Library/DefaultTextureAtlasImportSettings.asset failed.

I guess this means no then right?

Oct 03 '11 at 03:54 PM DanKripac
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

AssetDatabase.CreateAsset only takes a relative path and it's always inside the asset folder. You can't use a full path. All Unity-stuff that belongs to your project have to be placed inside the asset folder. If you don't want to include an asset into your build, just place it in an "editor" folder.

If you just want to store some settings you still can use plain .NET / Mono functions to write an xml file or something like that. This one you can place where ever you want, but your should leave the library folder alone. There's no reason to place anything in there. You can create a seperate folder for your stuff ("config" or something like that).

But again all assets that are under control of Unity have to be placed inside the assets folder

more ▼

answered Oct 03 '11 at 05:54 PM

Bunny83 gravatar image

Bunny83
45.2k 11 49 207

Thanks! this is pretty much the conclusion that I came to eventually. :) Good to be reminded of 'Editor' folders also excluding items from the build. Cheers!

Oct 03 '11 at 07:37 PM DanKripac
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x419
x74

asked: Oct 03 '11 at 03:44 PM

Seen: 1123 times

Last Updated: Oct 04 '11 at 09:02 PM