Trying to clone

Godot Version

extends Node2D

var sprite = preload(“res://sprite.tscn”)

func _process(delta):
if Input.is_action_just_pressed(“click”):
var s = sprite.instance()
s.position = get_global_mouse_position()
add_child(s)

Question

When i try to play this error comes: Invalid call. Nonexistent function ‘instance’ in base ‘PackedScene’. And I want it to spawn randomly on y axis

The error means, that the function instance() doesn’t exist

Try instantiate().

Usually you can find the names of the available functions in the docs, see here for example: PackedScene — Godot Engine (latest) documentation in English

2 Likes

its working butt can you tell how i ccan make it spawn randomly att y axis?

s.position.y = randf_range(-4, 6.5)

You can find information about creating random numbers in the documentation here: Random number generation — Godot Engine (latest) documentation in English

You can find information about accessing components of vectors in the documentation here: Vector2 — Godot Engine (latest) documentation in English

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