Quantcast
Channel: Questions in topic: "loadassetatpath"
Viewing all articles
Browse latest Browse all 62

Importing Textures not working quite right with LoadAssetAtPath?

$
0
0

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);

     AssetDatabase.Refresh();
     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


Viewing all articles
Browse latest Browse all 62

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>