Search Unity

Resolved error CS8805: Program using top-level statements must be an executable.

Discussion in 'Editor & General Support' started by Huwey, Apr 15, 2023.

Thread Status:
Not open for further replies.
  1. Huwey

    Huwey

    Joined:
    Mar 17, 2019
    Posts:
    29
    What is this error and how do I fix it?

    It doesn't give me any information as to what or where the error is at.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,141
    Sounds like a line of code is accidentally outside it's class/method. I'd have to see the code to say for certain.
     
  3. Huwey

    Huwey

    Joined:
    Mar 17, 2019
    Posts:
    29
    I actually found it, I copied all my scripts to another folder as a backup and removed each of them from my game and when it left I looked at that script and found the issue.

    Code (CSharp):
    1. using UnityEngine.Audio;
    2. using UnityEngine;
    3.  
    4. {
    5. }
    6.  
    7. public class SettingsMenu : MonoBehaviour
    8. {
    9.     public AudioMixer audioMixer;
    10.    public void SetVolume (float volume)
    11.     {
    12.         audioMixer.SetFloat("volume", volume);
    13.     }
    14.    
    15. }
    16.  
    The {} prior to the public class was the issue.

    I googled it and people were talking about having double ; but i didn't have that issue. it was the {} out of place.

    Luckily I only have about 15 scripts to go through. There was no indication of what file the issue was in.
     
    metalkidcn likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    Yes there was. You need to learn how to read error messages.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly?

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.
     
    atenajoon likes this.
  5. IneptStudio

    IneptStudio

    Joined:
    Mar 7, 2022
    Posts:
    12
    Just open the latest scripts you worked in and find a "; ;" two consecutive semicolons just after you "using UnityEngine...." statement , just remove one and it will work fine
     
    Deus69xxx and chandrajitsinh like this.
  6. unity_wApcI5DpvpFvuA

    unity_wApcI5DpvpFvuA

    Joined:
    Aug 1, 2021
    Posts:
    1
    some Time in Code make "{}" after "Using ....." .
    using UnityEngine.UI;
    {
    }
    public Class......
    {
    }
     
  7. chandrajitsinh

    chandrajitsinh

    Joined:
    Mar 28, 2020
    Posts:
    2
    It workd thanks man!
     
Thread Status:
Not open for further replies.