- Home /
AssetDatabase.LoadAllAssetsAtPath(...) Yields Mysterious Nameless Asset
I have some code that uses AssetDatabase.LoadAllAssetsAtPath(string assetName) to create some assets that are put into an asset bundle. The assets are mostly images and text. The code looks like this:
foreach(string assetPath in assetPathsList) { UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); foreach(UnityEngine.Object asset in assets) { writer.WriteLine(assetPath + "::" + asset.name + " (Type: " + asset.GetType().ToString() + ")"); assetList.Add(asset); } }
For most of the assets I expect the size of the array to be 1 but in every case I get back two assets in the array. Here's some of the output:
Assets/Text/file.xml::file (Type: UnityEngine.TextAsset) Assets/Text/file.xml:: (Type: UnityEngine.Object) ... Assets/Graphics/image.png::image (Type: UnityEngine.Texture2D) Assets/Graphics/image.png:: (Type: UnityEngine.Object)
file.txt is an xml file and so is correctly listed as a TextAsset. But what is the second one shown as a UnityEngine.Object? You can see similar results with the png. There is the expected UnityEngine.Texture2D and then the mysterious UnityEngine.Object. What is that?
can you post the entire script, please? I'd like to see how you initialise your list and path.
Answer by Lee Falin · Feb 12, 2010 at 04:18 AM
The UnityEngine.Object is the parent class that the TextAsset object inherits from. If you want just the subclass, try LoadMainAssetAtPath instead:
foreach(string assetPath in assetPathsList)
{
UnityEngine.Object asset = AssetDatabase.LoadMainAssetAtPath(assetPath);
writer.WriteLine(assetPath + "::" + asset.name + " (Type: " + asset.GetType().ToString() + ")");
}
Your answer
Follow this Question
Related Questions
How to save assets fast (AssetDatabase.CreateAsset) 0 Answers
How to remove an asset package 1 Answer
.Asset vs .Prefab vs. .Unity3d ? 1 Answer
Can AssetDatabase.LoadAllAssetsAtPath Load All Assets Recursively? 2 Answers
Addressables - Use Asset Database (faster) - Not loading assets within a folder 1 Answer