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: https://goo.gl/i4VvyQ
Here is the Spawn Menu Tree: https://goo.gl/Jwm82t
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)