Importing Textures not working quite right with LoadAssetAtPath?

Hi All

Iam trying to import textures manually from a text file with the code:

Texture2D ImportTexture(string path)
     string destpath = System.IO.Directory.GetCurrentDirectory() + "/";

     System.IO.Directory.CreateDirectory(Path.GetDirectoryName(assetPath) + "/Textures");

     string assetpath = Path.GetDirectoryName(assetPath) + "/Textures/" + Path.GetFileName(path);

     File.Copy(path, destpath + assetpath, true);

     return (Texture2D)AssetDatabase.LoadAssetAtPath(assetpath, typeof(Texture2D));

The problem being the textures get added and show up in Unity but the method LoadAssetAtPath returns a 'null' even though the texture is there, but oddly if I do a reimport then LoadAssetAtPath works fine and returns the Asset. Am I missing a step somewhere? Thanks Chris

It takes time for the asset importer to import the file, which I think happens asynchronously before calling back into the user importer scripts

You could try waiting a short while before trying again

I fixed this by calling Refresh() twice, like:


Yeah I get the same thing. I need to reimport once in a while. Must be a bug.