EllanJiang/GameFramework · error · GameFrameworkException

Sound helper is invalid.

Error message

Sound helper is invalid.

What it means

Thrown by SoundManager.SetSoundHelper when the soundHelper argument is null. The sound helper is mandatory for SoundManager operation (later code such as AddSoundAgentHelper explicitly requires it), so setting a null helper is rejected.

Solutions

  1. Attach/create a valid ISoundHelper implementation and pass it
  2. Check that GetComponent<SoundHelper>() did not return null before calling
  3. Verify initialization order: helper creation precedes SetSoundHelper

Example fix

// before
m_SoundManager.SetSoundHelper(GetComponent<SoundHelper>()); // may be null
// after
var helper = GetComponent<SoundHelper>();
if (helper != null) { m_SoundManager.SetSoundHelper(helper); }
Defensive patterns

Strategy: validation

Validate before calling

if (soundHelper == null) throw new InvalidOperationException("SoundHelper missing");
soundManager.SetSoundHelper(soundHelper);

Type guard

bool HasSoundHelper(ISoundHelper h) => h != null;

Try / catch

try { soundManager.SetSoundHelper(soundHelper); }
catch (GameFrameworkException ex) { Log.Error(ex.Message); }

Prevention

When it happens

Trigger: Calling soundManager.SetSoundHelper(null); passing a helper reference from a component that failed to resolve.

Common situations: Missing SoundHelper script attached to the game object; typos in GetComponent calls; scene setup omissions.

Related errors


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

Appendix: source

Thrown at GameFramework/Sound/SoundManager.cs:162

        public void SetResourceManager(IResourceManager resourceManager)
        {
            if (resourceManager == null)
            {
                throw new GameFrameworkException("Resource manager is invalid.");
            }

            m_ResourceManager = resourceManager;
        }

        /// <summary>
        /// 设置声音辅助器。
        /// </summary>
        /// <param name="soundHelper">声音辅助器。</param>
        public void SetSoundHelper(ISoundHelper soundHelper)
        {
            if (soundHelper == null)
            {
                throw new GameFrameworkException("Sound helper is invalid.");
            }

            m_SoundHelper = soundHelper;
        }

        /// <summary>
        /// 是否存在指定声音组。
        /// </summary>
        /// <param name="soundGroupName">声音组名称。</param>
        /// <returns>指定声音组是否存在。</returns>
        public bool HasSoundGroup(string soundGroupName)
        {
            if (string.IsNullOrEmpty(soundGroupName))
            {
                throw new GameFrameworkException("Sound group name is invalid.");
            }

            return m_SoundGroups.ContainsKey(soundGroupName);

View on GitHub (pinned to d0c010b051)