How can I correct this? , Godot 3 to Godot 4

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

This works in Godot version 3.2, but in version 4.0.3 I get an error with get_used_cells()

extends Node2D

var map = TileMap

func _ready():
map = get_node(“TileMaps/TileMap”)
configure_camera()

func configure_camera():

get_node(“Player/Camera2D”).limit_left = map.get_used_cells()[-1].x * map.cell_size.x

get_node(“Player/Camera2D”).limit_right = map.get_used_cells()[map.get_used_cells().size() - 1].x * map.cell_size.x

enter image description here

Can you copy and paste the error from the Godot debugger, then edit your answer and add it in? That’d help us help you track it down :slight_smile: From a quick glance though, the second line, var map = TileMap doesn’t look valid, but hard to say without an error.

Tom Mertz | 2023-05-30 22:03

enter image description here

Rexerick | 2023-05-30 22:38

Yep. @Tom Mertz is correct (the error is in the image - though hard to read). Your map variable is null…

jgodfrey | 2023-05-30 22:39

Ah, based on your scene tree post, you have a character case error in your get_node() call. Notice your node is named Tilemaps, but the get_node() call is referencing TileMaps.

jgodfrey | 2023-05-30 23:34

I can’t see the images, I just see a :no_entry: symbol. But I trust @jgodfrey :wink:

Tom Mertz | 2023-05-31 00:20

Huh… Weird. I can see the images on my laptop, but not on my phone…

¯\_(ツ)_/¯

jgodfrey | 2023-05-31 00:24

new error
enter image description here

Rexerick | 2023-05-31 01:01

enter image description here

Rexerick | 2023-05-31 01:02

enter image description here

Rexerick | 2023-05-31 01:07

As documented, get_used_cells() requires a layer argument in Godot 4.x.

TileMap — Godot Engine (stable) documentation in English

jgodfrey | 2023-05-31 01:08

:bust_in_silhouette: Reply From: Rexerick

As documented, get_used_cells() requires a layer argument in Godot 4.x.

thaanks…