How to place a sprite on tilemap - Nonexistent function 'world_to_map' in base 'Tilemap'

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

func _process(_delta):

var mousetile = GameManager.tilemap.world_to_map(get_global_mouse_position())
var localPosition = GameManager.tilemap.map_to_world(mousetile)
var worldPosition = GameManager.tilemap.to_global(localPosition)

global_position = worldPosition

that is what i have at the moment, i am very new to scripting so i would appreciate any advice.

I also keep getting the ‘Nonexistent function ‘world_to_map’ in base ‘Tilemap’’ error. thank you

In godot 4:

  • TileMap’s world_to_map() is now local_to_map().
  • TileMap’s map_to_world() is now map_to_local().

Give those a try and see how you get on. These docs may also help:

TileMap — Godot Engine (stable) documentation in English

Upgrading from Godot 3 to Godot 4 — Godot Engine (stable) documentation in English

spaceyjase | 2023-05-31 13:03

Thank you! This has been the issue, I appreciate your help!!

ShinRamen | 2023-05-31 13:15

I’d recommend that someone copy @spaceyjase’s answer as an actual Answer. That way, the question will show as having been answered on the main Q&A page, which is helpful for people searching for an answer to a similar problem in the future.

jgodfrey | 2023-05-31 14:37

:bust_in_silhouette: Reply From: ShinRamen

In godot 4:

TileMap’s world_to_map() is now local_to_map().
TileMap’s map_to_world() is now map_to_local().
Give those a try and see how you get on. These docs may also help:

credit goes to spaceyjase

1 Like