Home / Unity / U25

Unity error: CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement — cause and fix

The method body contains an expression that cannot form a statement (a stray comparison or

ID
U25
Engine
Unity
Verification
官方文档引用
Frequency
未公开

Original message (verbatim)

CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

Placeholders such as %s / %d are kept verbatim from the engine source and are not replaced with concrete values.

Trigger

The method body contains an expression that cannot form a statement (a stray comparison or arithmetic, a literal, a wrong discard, or an expression used as a statement), and compilation reports CS0201.

Typical cause

C# allows only assignment, call, increment, decrement, await, and new expressions as statements; every other expression is treated as an invalid statement.

Step-by-step fix

  1. Assign the expression result to a variable or use it in an if or return.
  2. Remove the stray comparison or arithmetic expression written as a statement.
  3. Check that method call parentheses and semicolons are placed correctly.

Source links

Per-entry sources and capture date are listed at /sources#U25.

Related errors

Related Unity errors

Need an offline quick-reference checklist?

Atlas error library Pro pack: 123 error references (110 single + 13 merged) plus a quick-fix guide, $19 one-time purchase, delivered as electronic files.

View Pro pack / order

Back to the all-errors index Checkout and buy the Pro pack — $19.00