Loading a ScriptableObject in Pre-Export fails

Hi.

I’m trying to use AssetDatabase.LoadAssetAtPath to load a ScriptableObject instance in the Pre-Export callback, and it fails on Cloud Build. Locally, it works. I have even confirmed that the file exists on Cloud Build by calling System.IO.File.Exists(). I can see the asset and its meta file in the repo, too.

I tried loading a json-file from the same path, and that works just fine. I don’t want to use a json file, because that brings a whole lot of other issues when it comes to implementation of a custom inspector.

// This verifies that the file exists
string abcPathRelative = "Assets/AssetBundleConfig.asset";
string abcPathFull = Application.dataPath + "/AssetBundleConfig.asset";
Debug.Log("[BV] Does "+abcPathFull+" exist? "+(File.Exists(abcPathFull) ? "Yes" : "No"));

// This returns 0
string[] configs = AssetDatabase.FindAssets("t:AssetBundleConfig");
Debug.Log("[BV] Found "+configs.Length+" AssetBundleConfig files");
foreach (string c in configs) {
    Debug.Log("[BV] config: "+AssetDatabase.GUIDToAssetPath(c));
}

// This one fails
AssetBundleConfig config = AssetDatabase.LoadAssetAtPath<AssetBundleConfig>(abcPathRelative);
if (config == null) {
    Debug.Log("[BV] Cannot load AssetBundleConfig from " + abcPathRelative);
}

Is this is a known problem with Cloud Build?

It works when I move the ScriptableObject class definition out of the namespace.

How come this is an issue only on Cloud Build, and not locally? What’s different between the Unity application running on the Cloud Build servers and my local installation?

After investigating this issue for more than a week now, I have found a solution. I have no idea why it works, but at this point I don’t care anymore.

I have a set of files in Assets/Scripts/AssetBundles, and they are all in the namespace Client.AssetBundles. Among them is a ScriptableObject called AssetBundleManagerConfig. An instance of this ScriptableObject is put in Assets/Configs.

In Cloud Build’s Pre-Build callback, I load the ScriptableObject instance using AssetDatabase.LoadAssetAtPath, and it fails.

The only way I have managed to make AssetDatabase load the file is by moving the class definitions (.cs-files) out of Assets/Scripts/AssetBundles. They can still be in the same namespace, just not in the same folder. I have tried for over a week to understand why, and it’s still beyond me.