Follow

What is CS0236?

Symptoms

When trying to enter play mode, I'm receiving the error below:

error CS0236: A field initializer cannot reference the nonstatic 
field, method, or property `___'

Cause

The CS0236 error is caused when a non-local variable references a non-static variable. See the example below:

 

Instance Variables should not be assigned this way.

Here is how the error appears in this example:

error CS0236: A field initializer cannot reference the nonstatic 
field, method, or property `ExampleScript.playerObj'

Resolution

The error CS0236 is resolved by assigning the reference in a method such as Start() or Awake(). See below:

More Information

https://msdn.microsoft.com/en-us/library/5724t6za(v=vs.90).aspx

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.