How to avoid getting: "Asset bundles can not include Editor Objects (AssetMetaData)" error message

When I use:

UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath("Assets/test3/test-img.png");
Debug.Log(objs.Length);
BuildPipeline.BuildAssetBundle(null, objs, Application.dataPath + "/../bundle.test");

I get:

  • "2"
  • "Asset bundles can not include Editor Objects (AssetMetaData): assets/test3/test-img.png."

Maybe using AssetDatabase.LoadMainAssetAtPath() would help but I am not using neither BuildAssetBundleOptions.CollectDependencies nor BuildAssetBundleOptions.CompleteAssets.

Also AssetDatabase.LoadAssetAtPath() would not help because it requires a datatype.

(Actually I know how to solve this, but is so annoying that I decided to post it).

Considering that istead of a png, the asset may be anything, I circunvent this the following way:

    UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath("Assets/test3/test-img.png");
    UnityEngine.Object[] objs2 = new UnityEngine.Object[objs.Length];
    Debug.Log(objs.Length);

    for (int i = 0, j = 0; i < objs.Length; i++)
        if (objs*.GetType() != typeof(UnityEngine.Object))*
 _objs2[j++] = objs*;*_
 _*BuildPipeline.BuildAssetBundle(null, objs2, Application.dataPath + "/../bundle.test");*_
_*```*_
_*<p>Maybe using AssetDatabase.LoadMainAssetAtPath() would help but I am not using neither*_
_*BuildAssetBundleOptions.CollectDependencies nor BuildAssetBundleOptions.CompleteAssets.</p>*_