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

Not all code paths return a value

Discussion in 'Scripting' started by EliteWalrus, Jul 24, 2015.

  1. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    Nevermind, that was stupid
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You should keep your question, and maybe write down, what the problem was, and how did you solved it, so if next time someone is searching for the same answer, he don't needs to ask on the forum.
     
  3. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,738
    it is explained in the title though, im guessing he had a method that returns a value, that had a if else statement that did not not have a return for each condition.
     
  4. EliteWalrus

    EliteWalrus

    Joined:
    Aug 16, 2014
    Posts:
    44
    That's exactly what happened. I doubt it would have actually helped anyone.
     
  5. Nyxxakai

    Nyxxakai

    Joined:
    Jun 14, 2012
    Posts:
    41
    I get this quite often when writing Ienumerator functions. So far, usually solved by starting the function with:

    if(isRunning)
    {
    yield break;
    }

    I'm still feel pretty noob at coding.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Just throw in a return null as the last line of code. ;)
     
  7. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    I think that's a fantastic way to get invisible errors in your logic. I'm usually pretty strict on myself not to take shortcuts- I'd rather have an error that I can see than logic problems that take six hours to narrow down to a premature break in a coroutine. *shudders*

    Waiting the two seconds for the red to pop up or not pop up in the status bar is nerve-wracking after awhile though.
     
    Kiwasi likes this.
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Yup. It's generally a bad idea. I only actually use it in coroutines.