Home / Unity / U28

Unity error: CS0120: An object reference is required for the non-static field, method, or property 'member' — cause and fix

An instance member is called directly from a static method or static context (an instance

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

Original message (verbatim)

CS0120: An object reference is required for the non-static field, method, or property 'member'

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

Trigger

An instance member is called directly from a static method or static context (an instance field or method accessed without new-ing the object), and compilation reports CS0120.

Typical cause

Instance members depend on a concrete object; the static context has no this reference, so the compiler rejects direct access.

Step-by-step fix

  1. Create an instance of the class and access the member through that object.
  2. Or make the called member static if it does not depend on instance state.
  3. Check that the singleton or reference is passed into the static method.

Source links

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

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