Sprites from one scene to another! That's at least what I'd like

Godot Version

Godot 4.3 / 2D

Question

Godot 2D
I would like to know if there is a way to move sprites with all their properties and characteristics from one scene to another? Example: the player in a scene drops a weapon. This weapon, another scene (which can be an area2d dropped on the ground) adds that weapon sprite as a child.

Of course you can. Depends how you manage scenes. Most universal method will move target node to autoload node.

1 Like

could I for example take the sprite as a variable and send it to a func in the other scene? and from the scene instantiate this sprite?

In-game? my_sprite.reparent(new_parent)

In-editor? copy and paste

1 Like

In my case I just wanted to copy, not separate from one scene to another

I was able to achieve this. I pass the Sprite as a variable to the other scene. The secret was to create a new Sprite by code and once created, the data is copied and this new Sprite is instantiated as a child. When I created the sprite in the inspector, copying the data did not work, at least I could not instantiate after copying.

The scene received the sprite in the following way:

func recibe_data(datos,sprite_arma_recibida:AnimatedSprite2D):
var spritee = AnimatedSprite2D.new()
spritee.sprite_frames = sprite_arma_recibida.sprite_frames
spritee.scale = sprite_arma_recibida.scale
get_node(“Marker2D”).add_child(spritee)
ruta_del_arma_drop=datos

You can use .duplicate() to speed this up too

func recibe_data(datos,sprite_arma_recibida:AnimatedSprite2D):
    $Marker2D.add_child(sprite_arma_recibida.duplicate())
1 Like

It is God that method <3

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