Bug: compile error when using USE_ADDRESSABLES

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
lgarczyn
Posts: 30
Joined: Fri May 05, 2023 5:28 am

Bug: compile error when using USE_ADDRESSABLES

Post 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;
        }

User avatar
Tony Li
Posts: 22098
Joined: Thu Jul 18, 2013 1:27 pm

Re: Bug: compile error when using USE_ADDRESSABLES

Post by Tony Li »

Hi,

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