Grid.GetCellCenterWorld not working. Is it a bug, or outdated?

,

I have written the following code:

    public Vector3 SnapCoordinateToGrid(Vector3 position) {
        Vector3Int cellPos = gridLayout.WorldToCell(position);
        position = grid.GetCellCenterWorld(cellPos);
        return position;
    }

With the variables:
public GridLayout gridLayout;
private Grid grid;

But i get the error:
Assets\Scripts\GridBuildingSystem.cs(53,25): error CS1061: ‘Grid’ does not contain a definition for ‘GetCellCenterWorld’ and no accessible extension method ‘GetCellCenterWorld’ accepting a first argument of type ‘Grid’ could be found (are you missing a using directive or an assembly reference?)

The line is: position = grid.GetCellCenterWorld(cellPos);

What am i doing wrong? There is a unity page for GetCellCenterWorld Unity - Scripting API: Grid.GetCellCenterWorld
But even if i try their example, i still get the same error.

I’m using Unity 2021.2.13f1 Personal.

Yep, it’s there and has been since Unity 2017.

I’ll guess you named one of your scripts Grid

Do I win the golden cookie?

2 Likes

Hopefully we’ll find out!

1 Like