c# add references and "using namespace" in my Godot project

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By fredaudy

Hi,

i use c#, and i want to know :

-1- i build an helper class, but i can’t access my helperClass namespace in the nodeScripts…??

-2- and, how can i add references in a godot project ??

-------------------- EDIT --------------------
Ok , for the point -1-, i got it : i have to create the file.cs in the Godot EDI, not in VSCode (or i must manually update the MyProject.csproj file)

:bust_in_silhouette: Reply From: Zylann

In Godot 3.0.2,m when using C#, you can use an IDE that lets you update the C# solution when adding files (like MonoDevelop or VisualStudio. Perhaps VSCode has a way to do it as well with a plugin?).
C# is not like GDScript, it needs a project file to be compiled. So if you use a text editor without project management you indeed need to do that manually, or force Godot to recreate or update the solution somehow.

Adding references is the same. If you have an IDE that lets you update the project file, then I believe you can add them that way.

:bust_in_silhouette: Reply From: imekon

I wanted to add a class like this:

public enum State
{
    Idle,
    Empty,
    Filling,
    Dropping,
    Swapping,
    Deleting
}
    
public class Cell
{
    public int Row;
    public int Column;
    public int Index;
    public State State;
    
    public Cell(int row, int column, int index)
    {
        Row = row;
        Column = column;
        Index = index;
        State = State.Idle;
    }
}

How do you do it in Godot?

I created Cell.cs with File → New in the scripting window - it insisted I derive from a Godot class like Node. So, I let it do that, then I removed the Node reference and made my classes like above. That got me an extra set of classes.

I don’t know the answer to adding references to external assemblies.

Hello, I’ve got the same problem. Could you find a solution? I’d like to work from VisualStudio without the need of creating “Scrips” manually from Godot app

martinlizo | 2020-03-26 12:31