Search Unity

Getting a namespace definition error whenever i load a script into VS Code?

Discussion in 'Scripting' started by RyanPwn, Dec 8, 2018.

  1. RyanPwn

    RyanPwn

    Joined:
    Sep 11, 2018
    Posts:
    1
    Hi there, every time I load up a new script it gives me this error

    Code (CSharp):
    1. The namespace '<global namespace>' already contains a definition for 'PlannetGravity' [Assembly-CSharp]
    it seems to not matter what i name it, because a file that was previously working now throws this error. ^

    Here is the code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlannetGravity : MonoBehaviour {
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.      
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.      
    15.     }
    16. }
    17.  
    How should i fix this? Is it a unity error or a VS Code error?

    Thanks <3

    (EDIT: After restarting VS Code, it has a chance to start working. Could it be a problem with omnisharp?
     
  2. chubbspet

    chubbspet

    Joined:
    Feb 18, 2010
    Posts:
    1,220
    you might have duplicated or renamed the script without the compiler picking it up.
     
  3. AtitudeGames

    AtitudeGames

    Joined:
    Dec 23, 2018
    Posts:
    3
    i have the same problem. and the file not is duplicated, you find a solution?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @AtitudeGames and @RyanPwn

    ...happens here also since 2018.2 but maybe it's just the new VS Code version.

    It has nothing to do with actual duplicates, usually I get this when I create a new script.
    This is how I've managed to avoid it:

    1. Close VS Code

    2. Select the offending script in Unity

    3. Right click and select Reimport (not Reimport All)

    4. Refresh and wait that scripts get compiled.

    5. Restart VS Code

    This usually has fixed the error... so far.
     
  5. MichaelNielsenDev

    MichaelNielsenDev

    Joined:
    Apr 17, 2014
    Posts:
    10
    I keep getting the same problem. Can confirm there is no duplicate. Has this been fixed in newest Unity / VS Code?
     
  6. Shizola

    Shizola

    Joined:
    Jun 29, 2014
    Posts:
    476
    This is really annoying, I'm having to restart vscode every time I create a new script.