tilemap.WorldToCell() not returning correct position.

So I’m trying to keep track of the player’s current cell position, using the below code. Everything was working fine until I copied over my code to a new script. I checked transform.position and it is returning the correct position every update. I’m not sure if there is an issue with referencing the Tilemap when I switched over to the new script. I drug my Ground Tilemap–which is the child of Tilemap Grid-- to the project window to create a prefab, then drug that prefab into the reference of my Player Behavior script. This was the only way I found to get a reference to a component of the right type, although when clicking the bullseye it says there are no Tilemaps in my project.

    public Tilemap groundTilemap; //Get reference to ground tilemap

void Update()
    {
        currentCell = groundTilemap.WorldToCell(transform.position); //Update cell location of player
    }

Does this help? I don’t know if it makes a difference but sometimes the player transform ends up on a different z axis position than the tilemap.

groundTilemap.WorldToCell(new Vector3(transform.position.x, transform.position.y, groundTilemap.transform.position.z));

You may also want to check on the exact pivot point of the player.

So I double checked and the player and the Tilemap are both set to z. Tried making the suggested change, but position is not a property of Tilemap. So I used groundTilemap.orgin.z instead and it still doesn’t work

So I was able to get it fixed after working on it again today. I believe there was an issue with the reference to the Tilemap. I was able to bring in the reference to the actual instance in the scene and not the prefab and it worked.