How do I make an object self duplicate itself ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Landro974

I am new to game developing, and I want an object to duplicate itself at an event. I tried with

if event :
self.duplicate()

but it didn’t do anything.

:bust_in_silhouette: Reply From: stephann

I’m not sure, but I think you will need to add duplicated object to scene.

var dup = self.duplicate()
self.get_parent().add_child(dup)
1 Like
:bust_in_silhouette: Reply From: iNeedMentalHelp

Although I haven’t tried this, I’d do it like this:

var nodeSelf = load("../nameOfTheNodeYoureGonnaduplicate").instance()
get_tree().current_scene.add_child(nodeSelf)

Edit: And do not remove the 2 dots

I don’t know how to help you anymore as I use v3.5.2 since I’d have to rewrite most of the code I already have written

iNeedMentalHelp | 2023-06-25 10:49