Scene not instantiating at Marker2D Position in Level

Godot Version

4.2

Question

Hi,

I want to spawn a CharacterBody2D at a certain position. However it seems to be offset for some reason.

Here is the overall level. I added a ColorRect to the Marker2d to make it more visible.

Here is the code for the spawning logic

extends Marker2D

const WORKER = preload("res://worker.tscn")

func _on_timer_timeout() -> void:
	var new_worker = WORKER.instantiate()
	new_worker.global_position = global_position
	add_child(new_worker)

Wondering what obvious thing I am getting wrong :slight_smile:

new_worker.position = global_position

Seems to still be the same issue. Added some print statements

	var new_worker = WORKER.instantiate()
	print("global_position" + str(global_position))
	print("position" + str(position))
	new_worker.position = global_position
	add_child(new_worker)

And the output

global_position(990, 497)
position(990, 497)

So both are the same

do not instantiate the worker in Marked2D, but query the Marked2D position and then instantiate the worker

1 Like

Cheers, works now when I moved the logic to the level

extends Node2D
const WORKER = preload("res://worker.tscn")
@onready var worker_spawner: Marker2D = %WorkerSpawner

func _on_spawner_spawn_scene() -> void:
	var new_worker = WORKER.instantiate()
	new_worker.global_position = worker_spawner.global_position
	add_child(new_worker)

Why is this different though?

1 Like