0 votes

I keep having this problem where it doesn't instance my scene more then once which is really annoying me

extends Area2D

#Coordonates and position
var cell_size = 1

var x = get_global_mouse_position().x
var y = get_global_mouse_position().y
export var cube_thing = preload("res://Scene.tscn")
var Scene = cube_thing.instance()

#Hidden mouse
func _ready(): 
    set_process_input(true)
    Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
    $Sprite.position = get_global_mouse_position()

#Actual movement
func _input(event):
    if event is InputEventMouseButton:
        self.add_child(Scene)
in Engine by (110 points)

1 Answer

+2 votes
Best answer

Hi,
You're instancing the same scene in the same place.
If you want to do that, then set the position before you instance it.
If you want more than one instance, move the instance() call:

func _input(event):
    if event is InputEventMouseButton:
        var Scene = cube_thing.instance()
        Scene.position = get_global_mouse_position()
        self.add_child(Scene)
by (1,921 points)
selected by

Thank you so much!!
You just solved something I had problem with for weeks and had no idea how to approach!!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.