Page 1 of 1

Bug: compile error when using USE_ADDRESSABLES

Posted: Mon Jan 29, 2024 6:12 pm
by lgarczyn

Code: Select all

        private static AudioClip LoadAudioClip(string audioFileName)
        {
#if UNITY_EDITOR || USE_ADDRESSABLES
            AudioClip audioClip;
#if UNITY_EDITOR
            audioClip = Resources.Load<AudioClip>(audioFileName);
            if (audioClip != null) return audioClip;

#if USE_ADDRESSABLES
            var settings = AddressableAssetSettingsDefaultObject.Settings;
            var allEntries = new List<AddressableAssetEntry>(settings.groups.SelectMany(g => g.entries));
            var foundEntry = allEntries.FirstOrDefault(e => e.address == audioFileName);
            if (foundEntry != null) audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(foundEntry.AssetPath);
            if (audioClip != null) return audioClip;
#endif
#endif
            return null;
        }
        
When USE_ADDRESSABLES is set, this code in PreviewUI.cs gives the error:

Assets\Plugins\Pixel Crushers\Dialogue System\Scripts\Options\Timeline\Playables\Utility\PreviewUI.cs(269,23): error CS0168: The variable 'audioClip' is declared but never used

The code should probably be something like

Code: Select all


        private static AudioClip LoadAudioClip(string audioFileName)
        {
#if UNITY_EDITOR
            AudioClip audioClip = Resources.Load<AudioClip>(audioFileName);
            if (audioClip != null) return audioClip;

#if USE_ADDRESSABLES
            var settings = AddressableAssetSettingsDefaultObject.Settings;
            var allEntries = new List<AddressableAssetEntry>(settings.groups.SelectMany(g => g.entries));
            var foundEntry = allEntries.FirstOrDefault(e => e.address == audioFileName);
            if (foundEntry != null) audioClip = AssetDatabase.LoadAssetAtPath<AudioClip>(foundEntry.AssetPath);
            if (audioClip != null) return audioClip;
#endif
#endif
#endif
            return null;
        }


Re: Bug: compile error when using USE_ADDRESSABLES

Posted: Mon Jan 29, 2024 8:29 pm
by Tony Li
Hi,

I'll make the change to silence that warning. Thanks for reporting it.