error CS0246: Showing in Unity but not Microsoft Visual Studio

Assets\Scripts\Game.cs(16,12): error CS0246: The type or namespace name ‘GloveData’ could not be found (are you missing a using directive or an assembly reference?)

I get this error in Unity but not visual studio and it is preventing me from testing my game.

This is the file throwing the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
[Serializable]
public class Game
{
    public DateTime alphaNext;
    public DateTime omegaNext;
    public int alphaCreds;
    public int omegaCreds;
    public int Level;
    public int Exp;
    public int Energy;
    public DateTime lastEnergy;
    public GloveData Fire;
}

I have another file in the same exact folder called GloveData.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
[Serializable]
public class GloveData
{
    public string Name;
    public int Level;
    public int Geme;
    public int Entergy;
    public int Star;
    public int Att;
    public int Def;
    public int Hp;
}

I have no problem calling the Game Class in another file, can’t figure what is wrong with these.

First make sure all your files are saved in VS (obviously)

Then try reimport the GloveData file.

Then try reimport ALL

After that, make sure your intellisense is properly set up:

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

Also, try update the VSCode package inside of Unity: Window → Package Manager → Search for Visual Studio Code Editor → Press the Update button

Also, this: No suggestions in Vscode

I ended up just combining GloveData and Game into one file and I seems to working just fine. It very well could have been something that got knocked out of sync I am not knowledgeable enough yet to fix. Thanks for the help anyways.

1 Like