TileMapLayer scene tiles don't have access to the rest of the tree

Godot Version

4.5

Question

I’m trying to make a simple platformer and am currently working on the checkpoint flags. Here is my problem. The checkpoint flags need access to the PlayerSpawnPoint node so that it can move the player spawn point around. However, the flags are scene tiles in the Level TileMapLayer node, and I can’t get them to access the nodes in the tree.
Does anybody know how I could do this?

Code + Scene Tree

extends Area2D #checkpoint_flag.gd

@onready var player_spawn_point: Marker2D = $%Level.get_node("$%PlayerSpawnPoint")


func _on_body_entered(body: Node2D) -> void:
	if body.name == "Player":
		player_spawn_point.position = position


The checkpoint flag is a scene tile in Level

A more complete version of your hierarchy looks like this:

Main
    Level
        CheckpointFlag         # this wants to see...
            Sprite2D
            CollisionShape2D
    Player
    PlayerSpawnPoint          # ...this

There’s a variety of ways you can do that:

  • $"../../PlayerSpawnPoint – go up two levels, look there
  • $/root/Main/PlayerSpawnPoint – absolute path
  • $"../..".get_node("PlayerSpawnPoint") – with get_node()

You could also have a script on Main that writes self into a variable in CheckpointFlag.

1 Like

This works. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.