EllanJiang/GameFramework · error · GameFrameworkException

Sound group name is invalid.

Error message

Sound group name is invalid.

What it means

This error is thrown by the SoundGroup constructor when the group name is null or an empty string. GameFramework requires every sound group to have a non-empty name because the name is used as the dictionary key in SoundManager's m_SoundGroups. It is a fail-fast guard against constructing an unusable group object.

Solutions

  1. Pass a non-empty, non-null name to the SoundGroup constructor
  2. Validate/trim the name string before constructing the group
  3. Fix the config or editor field that supplies the sound group name

Example fix

// before
var group = new SoundGroup(name, helper); // name may be null/empty
// after
if (string.IsNullOrEmpty(name)) { name = "Default"; }
var group = new SoundGroup(name, helper);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(name)) throw new ArgumentException("Sound group name required");
var group = new SoundGroup(name, helper);

Type guard

bool IsValidGroupName(string name) => !string.IsNullOrEmpty(name);

Try / catch

try { var group = new SoundGroup(name, helper); }
catch (GameFrameworkException ex) { Log.Error(ex.Message); }

Prevention

When it happens

Trigger: Calling new SoundGroup(name, soundGroupHelper) with name == null or name == "". Also reached indirectly via SoundManager.AddSoundGroup if that method were bypassed, though AddSoundGroup validates first.

Common situations: Loading sound group names from configuration files or an inspector field that was left blank; passing an uninitialized string variable; string splitting that yielded an empty segment.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of EllanJiang/GameFramework@d0c010b051 (2026-09-15). Data as JSON: /api/errors/0c723ae2598341ad. Report an issue: GitHub.

Appendix: source

Thrown at GameFramework/Sound/SoundManager.SoundGroup.cs:35

        private sealed class SoundGroup : ISoundGroup
        {
            private readonly string m_Name;
            private readonly ISoundGroupHelper m_SoundGroupHelper;
            private readonly List<SoundAgent> m_SoundAgents;
            private bool m_AvoidBeingReplacedBySamePriority;
            private bool m_Mute;
            private float m_Volume;

            /// <summary>
            /// 初始化声音组的新实例。
            /// </summary>
            /// <param name="name">声音组名称。</param>
            /// <param name="soundGroupHelper">声音组辅助器。</param>
            public SoundGroup(string name, ISoundGroupHelper soundGroupHelper)
            {
                if (string.IsNullOrEmpty(name))
                {
                    throw new GameFrameworkException("Sound group name is invalid.");
                }

                if (soundGroupHelper == null)
                {
                    throw new GameFrameworkException("Sound group helper is invalid.");
                }

                m_Name = name;
                m_SoundGroupHelper = soundGroupHelper;
                m_SoundAgents = new List<SoundAgent>();
            }

            /// <summary>
            /// 获取声音组名称。
            /// </summary>
            public string Name
            {
                get

View on GitHub (pinned to d0c010b051)