Skip to main content
Discovery icon for Official Unity Discord Discord server

Official Unity Discord

32,909 Online
140,022 Members
# 💻┃code-beginner3 people

collection modified in foreach loop

Modifying a collection during a foreach loop caused errors when float imprecision broke binary search matching during object insertion.

  • Modifying an array or collection during a foreach loop can trigger collection modified exceptions if callbacks insert new elements
  • A helper function used BinarySearch to find existing beat lines and inserted a new line if not found
  • Floating-point imprecision from adding and subtracting beat offsets caused binary search to miss existing lines and attempt unwanted inserts
  • The issue was fixed by creating a specialized function that directly assigns the line without calling insertion logic
Summarized from recent messages, might be inaccurate

More conversations

Talk, Play, &
Hang Out

Find your space to hang out, discuss the latest updates with the party chat, and see who's down to join your next match.
Get App