'Tilemap' does not contain a definition for 'SetTile'

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class Tilemap : MonoBehaviour
{
    [SerializeField] private Vector2Int gridSize;
    [SerializeField] private Tile tileA;

    // Start is called before the first frame update
    void Start()
    {
        Tilemap tilemap = GetComponent<Tilemap>();

        for (int x = 0; x < gridSize.x; x++)
        {
           for (int y = 0; y < gridSize.y; y++)
           {
               tilemap.SetTile(new Vector3Int(x,y,0), tileA);
           }
        }
    }
}

This code prompts an error in the console: “Assets\Tilemap.cs(20,24): error CS1061: ‘Tilemap’ does not contain a definition for ‘SetTile’ and no accessible extension method ‘SetTile’ accepting a first argument of type ‘Tilemap’ could be found (are you missing a using directive or an assembly reference?)”

This happens with any Tilemap method, including the example code in something like SetTilesBlock, for example.

Hi @natewbrooks ,

Your class name is the same as the Unity’s Tilemap which you try to use from UnityEngine.Tilemap namespace.

Rename that class to something else like MyTilemap and also rename the script file to the same name and that error will go away.

And if you really insist that you want to use the same name, then you can refer to that actual Unity tilemap by using UnityEngine.Tilemaps prefix for Tilemap at line 14 etc.

Or create an alias with “using” keyword.

Oh my gosh, stupid mistakes. Thank you for steering me in the right direction!

Good that you got it sorted out.

P.S. Looks like a typo sneaked in to my answer. It was supposed to say UnityEngine.Tilemaps.