Invalid type in function 'set_pos' in base 'KinematicBody2D'. Cannot convert argument 1 from Object to Vector2.

: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 stumped, how do I fix this? I cant find a solution anywhere else.

extends Position2D

export (PackedScene) var spawnScene
onready var spawnReference = load(spawnScene.get_path())
onready var sprite = get_tree().get_root().get_node("World/Player/PlayerSprite")
onready var sound = get_parent().get_node("World/Player/BulletSpawn/Bullet/Sound")#/Sound").get("Shoot")

#var bullet = self
var velocity = Vector2()
var speed = 1.25
var ammo = 12
var canShoot = true

export var BulletSpeed = 1500.0
export var Smoothness = 0.2

func _ready():
	set_fixed_process(true)
	set_process_input(true)
	
	
#func _fixed_process(delta):

func _input(event):
	var spawnInstance = spawnReference.instance()
	var direction = 3.0
	
	if event.type == InputEvent.KEY:
		var key = event.scancode
		var pressed = event.is_pressed()
		var echo = event.is_echo()
        
		if key == KEY_Q and pressed and not echo:
			print("Fired")
			spawnInstance.set_pos()
			get_parent().add_child(spawnInstance)
			sprite.set_flip_h(true)
			ammo -= 1
        
		elif key == KEY_E and pressed and not echo:
			print("Fired")
			spawnInstance.set_pos()
			get_parent().add_child(spawnInstance)
			sprite.set_flip_h(false)
			ammo -= 1
:bust_in_silhouette: Reply From: kidscancode

You didn’t say where exactly in that code the error is happening.

One thing I notice: you use spawnInstance.set_pos(), but set_pos() requires an argument - you have to set the position to something.

Also, this:

func _input(event):
    var spawnInstance = spawnReference.instance()

Is not a good thing. You’re spawning an instance of that scene every time the input function is called. But that happens on any input event, including mouse movement, etc.

In general, it’s a better idea to use the input map and create input actions for any input you want to process. That way it’s easier to change input keys, transition to gamepad or touch, etc.

Whoops, its at line 36 and 43…

HarryCourt | 2017-11-19 05:17

So it’s what I answered: you have to supply a Vector2 for set_pos() to set the position of a node.

kidscancode | 2017-11-19 05:58