Follow

What is CS0161?

Symptoms

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

error CS0161: `___': not all code paths return a value

Cause

The CS0161 error is caused when one or more outcomes of a method with a return type do not return a value.

In the example below we have a method that uses a GameObject as the return type. This means that all outcomes in this method must return a GameObject or the null value. The Script shown below does not return a value in all outcomes.

Here is how the error appears in this example:

error CS0161: `ExampleScript.SpawnEnemy(int)': not all code paths return 
a value

Resolution

The error CS0161 is resolved by ensuring that all outcomes in the method return a value of the type defined. In this Example we have defined "GameObject" as the return type. We have fixed this example by ensuring that all outcomes return a value.

More Information

https://msdn.microsoft.com/en-us/library/87cz4k9t.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.