How to spawn in an instance at a Position2D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HarryCourt
:warning: Old Version Published before Godot 3 was released.

I’m trying to make a script where once a button is pressed, it will spawn a prefab into the scene. However, I can’t get it to work and get this message: Cannot convert argument 1 from Object to Vector2

Here is the code:

extends Button

# Items
onready var bathtub = load("res://Prefabs/Items/Bathtub.scn")

# Variables
onready var spawner = get_node("/root/Scene/Player/Spawner")

# Once pressed, the item will spawn on the Players Spawner node
func _on_Button_pressed():
	print("Spawned Item")
	var bathtubSpawn = bathtub.instance()
	bathtubSpawn.set_position(spawner)
	add_child(bathtub)

Here is my Player Node Tree: Screenshot - 4507862ac2d605311671d049546ff783 - Gyazo
Here is the Spawn Menu Tree: Screenshot - dc7c28397451b1515f2a62ce8dcc1840 - Gyazo

EDIT: I slightly fixed it, but instead of it spawning on the spawner, it spawns on the Scene Root Pos (0, 0). Here is the new code

extends Button

# Items
onready var bathtub = load("res://Instances/Items/Bathtub.scn")

# Variables
onready var spawner = get_node("/root/Scene/Player/Spawner")
onready var world = get_node("/root/Scene")

# Once pressed, the item will spawn on the Players Spawner node
func _on_Button_pressed():
	print("Spawned Item")
	var bathtubSpawn = bathtub.instance()
	bathtubSpawn.set_position(spawner.get_position())
	world.add_child(spawner)
:bust_in_silhouette: Reply From: Skyfrit

You need to get the spawner position.

Godot 3
bathtubSpawn.set*_*position(spawner.get_position())

bathtubSpawn.position = spawner.position

Godot 2
bathtubSpawn.set*_*pos(spawner.get_pos())

Doesn’t work, it doesn’t spawn anything, but it does register the button press

HarryCourt | 2017-12-20 06:44

I’m sorry, I make a mistake.

You should use get*_*global_position().

bathtubSpawn.set*position(spawner.get*global_position())

Skyfrit | 2017-12-20 18:19