Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

TemplateScript.gggg()': not all code paths return a value

Discussion in 'Scripting' started by pKallv, Oct 24, 2014.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,122
    Could someone explain to me what i am doing wrong with this code?

    I have a function:
    Code (csharp):
    1. void DoTemplateFile(List<MaxType>theMaxTypeList) {"
    In this function i have:
    Code (csharp):
    1. StartCoroutine (gggg());
    And I have a coroutine that looks like this:
    Code (csharp):
    1.  
    2. IEnumerator gggg() {
    3.     //testing
    4.  }

    I get the following Error:
    Code (csharp):
    1. TemplateScript.gggg()': not all code paths return a value
    This code is a stripped down version as i removed all code in the coo routine when i got the problem to see if i could fix it.
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,377
    your method 'gggg' doesn't return anything, though it defines a return type. You need to return something.

    You could return null.

    You could return System.Linq.Enumerable<object>.Empty.GetEnumerator()

    You could 'yield break', making it an enumeration method

    But when you define a return type, you have to return something.
     
  3. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,122
    Interesting i just found that out myself as i had "yield return newWaitForSeconds(secondsRateToMaxl);" imbedded in the original code and it was when i rewrote it i did not include it. Thanks