Don't know how to create a clone of an object

Godot Version



I have a top down game and I wan’t to place down bombs or teleporters by making a clone of a scene but I don’t know how.

You could inherit the scene. I would suggest watching a video on ‘inheritance in Godot’.

thanks i will try that

but I wan’t it that when you push the z it creates a bomb an then it explodes(destroyes it’s self). like that I can make it that there can be more than one bomb while playing.

So, basically a shooting mechanic with projectiles(bombs)?

For doing that, you probably want to have a scene that is the bomb and a node that instanciates this scene. I use to call _prefab to the scene that is instantiated.

@export var bomb_prefab: PackedScene;

func spawn_bomb() -> void:
    var bomb_instance = bomb_prefab.instantiate();
    add_child( bomb_instance );

Remember to assign the exported variable in the editor. Of course this is a snippet, you may want the world to be the parent of the bomb: get_tree().root.add_child( bomb_instance ) for example or assign a position after that.

But answering your question, you first have to instantiate a scene and then add it to the scene tree, that’s how it works.

1 Like

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