1
votes

So im building a little game in unity and made a grid system with the help of a youtube tutorial so heres the code with the bug

public class GridBuildingSystem : MonoBehaviour
{
    private Grid<GridObject> grid;

    private void Awake()
    {
        int gridWidth = 38;
        int gridHeight = 38;
        float cellSize = 1f;
        grid = new Grid<GridObject>(gridWidth, gridHeight, cellSize, Vector3.zero, 
                                   (Grid<GridObject> g, int x, int y) => new GridObject(g, x, y));
}

public class GridObject
{
    private Grid<GridObject> grid;
    private int x;
    private int y;

    public GridObject(Grid<GridObject> grid, int x, int y)
    {
        this.grid = grid;
        this.x = x;
        this.y = y;
    }
}}

I get a CS1593(Delegate 'del' does not take 'number' arguments) on (Grid g, int x, int y) => new GridObject(g, x, y) but the constructor takes 3 arguments.

Edit: Maybe it has todo with this:

public class Grid<TGridObject> : MonoBehaviour
{
    private int width;
    private int height;
    private float cellSize;
    private Vector3 originPosition;
    private TGridObject[,] gridArray;
    private TextMesh[,] debugTextArray;

    public Grid(int width, int heigth, float cellSize, Vector3 originPosition, Func<TGridObject> createGridObject)
    {
        this.width = width;
        this.height = heigth;
        this.cellSize = cellSize;
        this.originPosition = originPosition;

        gridArray = new TGridObject[width, heigth];
        debugTextArray = new TextMesh[width, heigth];

        for(int x=0;x<gridArray.GetLength(0);x++)
        {
            for(int y=0;y<gridArray.GetLength(1);y++)
            {
                gridArray[x, y] = createGridObject();
            }
        }
    }
}

Hope anyone can help and have a nice day :D

What is CS1593? I don't actually have all of the error codes memorized.Chuck
its Delegate 'del' does not take 'number' argumentsxVice1337
GridObject is not a delegate, so it's not about that (your) constructor.madreflection
Time out: GridObject in class Grid<GridObject> is not the class GridObject you defined. There's a reason that type parameters, by convention, have a T prefix. No real class will have that prefix so they can't be confused. Use that convention: class Grid<TGridObject> or just class Grid<T>.madreflection
Func<GridObject> createGridObject is a delegate with 0 arguments that returns a GridObject. This method you're passing to it ((Grid<GridObject> g, int x, int y) => new GridObject(g, x, y)) has 3 arguments and returns a GridObject. Clearly they don't describe the same method.DiplomacyNotWar