Unity-Technologies/UnityCsReference · error · ArgumentNullException

list

Error message

list

What it means

Thrown by TickHandler.GetTicksAtLevel(int, bool, List<float>) when the caller-supplied list is null. The method populates the list in place (and the sibling overload returns an array); a null list cannot be added to, so the guard throws ArgumentNullException(nameof(list)) before the loop.

Source

Thrown at Editor/Mono/Animation/TickHandler.cs:153

            m_MinValue = minValue;
            m_MaxValue = maxValue;
            m_PixelRange = maxPixel - minPixel;
        }

        public float[] GetTicksAtLevel(int level, bool excludeTicksFromHigherlevels)
        {
            if (level < 0)
                return Array.Empty<float>();

            m_TickList.Clear();
            GetTicksAtLevel(level, excludeTicksFromHigherlevels, m_TickList);
            return m_TickList.ToArray();
        }

        public void GetTicksAtLevel(int level, bool excludeTicksFromHigherlevels, List<float> list)
        {
            if (list == null)
                throw new System.ArgumentNullException("list");

            int l = Mathf.Clamp(m_SmallestTick + level, 0, m_TickModulos.Length - 1);
            int startTick = Mathf.FloorToInt(m_MinValue / m_TickModulos[l]);
            int endTick = Mathf.CeilToInt(m_MaxValue / m_TickModulos[l]);
            for (int i = startTick; i <= endTick; i++)
            {
                // Return if tick mark is at same time as larger tick mark
                if (excludeTicksFromHigherlevels
                    && l < m_BiggestTick
                    && (i % Mathf.RoundToInt(m_TickModulos[l + 1] / m_TickModulos[l]) == 0))
                    continue;
                list.Add(i * m_TickModulos[l]);
            }
        }

        public float GetStrengthOfLevel(int level)
        {
            return m_TickStrengths[m_SmallestTick + level];

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Allocate the list before calling: new List<float>() or reuse a cleared instance.
  2. If the array-returning overload fits, use GetTicksAtLevel(level, exclude) which handles its own list.
  3. Pool and clear, but never null: list ??= new List<float>(); list.Clear();.
  4. Validate at the call site and log the caller.

Example fix

// before
handler.GetTicksAtLevel(level, false, null);

// after
var ticks = new List<float>(64);
handler.GetTicksAtLevel(level, false, ticks);
Defensive patterns

Strategy: validation

Validate before calling

list ??= new List<float>(); list.Clear();

Prevention

When it happens

Trigger: Calling GetTicksAtLevel(level, exclude, null). Reusing a field that was cleared to null. Passing a List<float> pulled from a dictionary with TryGetValue that failed.

Common situations: Custom editor timeline/ruler drawing that reuses a tick list across repaints. Animation curve editor extensions. Tools that pool lists but occasionally null them out.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/49cf65dc5cd3aee0. Report an issue: GitHub.