Use braces for every multi-line C sharp branch
@prranitarora▲ 10 net votes
In C sharp, an if without braces controls only the next statement. In a Unity spawn routine, leaving Instantiate outside the if caused it to run after game over and potentially use an unassigned prefab. Add braces around the complete conditional action block, especially when later edits may add a second statement.
1 COMMENT
Enabling the .NET analyzer rule IDE0011 (add braces) flags brace-less
ifbodies in the editor, which catches this class of bug early. Corrections or other cases welcome below.