google-ar / arcore-unity-extensions

Google ARCore Extensions and Geospatial Creator for Unity's AR Foundation
Other
347 stars 97 forks source link

NullReferenceException during build #39

Open florius0 opened 3 years ago

florius0 commented 3 years ago

I was following official tutorial on Google Cloud Anchors and faced a problem. After setting up api key for iOS this exception raises during build-time when RuntimeConfig asset is created in LoadInstance.

My environment:

Unity 2020.3.0f1 LTS

Build platform: iOS

macOS 10.15.7

Instance is null

public static void LoadInstance()
        {
            if (Instance != null)
            {
                return;
            }

            string folderPath =
                AssetDatabase.GUIDToAssetPath(_runtimeFolderGUID) + _runtimeConfigFolder;

            Debug.Log($"folderPath = {folderPath}");
            if (!Directory.Exists(folderPath))
            {
                Debug.Log($"Does not exists, creating");
                Directory.CreateDirectory(folderPath);
            }

            string assetPath = folderPath + "/" + _runtimeConfigAsset;
            if (!File.Exists(assetPath))
            {
                Debug.Log("Created ARCore Extensions RuntimeConfig for Preloaded Assets.");
                var config = CreateInstance<RuntimeConfig>();
                AssetDatabase.CreateAsset(config, assetPath);
                Instance = config;
            }
            else
            {
                Instance = AssetDatabase.LoadAssetAtPath<RuntimeConfig>(assetPath);
            }
            Debug.Log($"assetPath = {assetPath}, exsists = {File.Exists(assetPath)}");
            Debug.Log(Instance);
        }

        public static void SetIOSApiKey(string apiKey)
        {
            LoadInstance();
            Instance.IOSCloudServicesApiKey = apiKey; // Instance is null, fails here
            UploadInstance();
        }

Note: I added some logging

May be the reason of this behaviour is attempt to create an asset in read-only directory? Log output:

folderPath = Packages/com.google.ar.core.arfoundation.extensions/Runtime/Configurations/RuntimeSettings
assetPath = Packages/com.google.ar.core.arfoundation.extensions/Runtime/Configurations/RuntimeSettings/RuntimeConfig.asset, exsists = True
assetPath = Packages/com.google.ar.core.arfoundation.extensions/Runtime/Configurations/RuntimeSettings/RuntimeConfig.asset, exsists = True
Null
RoselliSimone commented 3 years ago

I guess i have the same problem here, but my nullreference comes with a similar definition in the next method UploadInstance(). By the way, i´m not entirely sure if this has anything to do with the error, but it also freezes the editor during the build. I´m on version 1.24

florius0 commented 3 years ago

You can try to comment out call that causes error and add RuntimeConfig to preloaded assets manualy

SerJoCrosto commented 3 years ago

Привет! Столкнулся с похожей ситуацией. Действительно, ошибка появлялась из-за списка предзагруженных объектов в самом редакторе. В моем случае в списке было 2 элемента, где 1 почему-то был пуст. Я его удалил, тем самым исправил ошибку.

Hey! I faced a similar situation. Indeed, the error appeared due to the list of preloaded assets in the editor. In my case, there were 2 elements in the list, where first was null. I removed it, thereby fixing the error.