Can't add bow to 'Player' after colliding with 'bow_pickup'

Godot Version

Godot 4.2

Question

` Most likely a simple question for you guys but a horrible situation for me 5 days into Godot :smiley:

I am trying to add a bow to the Player after colliding with it. I have 3 scripts that are relevant: player.gd, bow_pickup.gd and bow_hold.gd.

player.gd is responsible for, well, the player

bow_pickup.gd is currently only responsible for a queue_free() function to delete bow_pickup.tscn once the node is collided with

bow_hold.gd is responsible for the firing of arrow.gd and tracking the mouse’s global position in bow_hold.tscn

The main problem is that once I collide with the bow_pickup scene, I have no idea how to add the bow_hold scene to the player - mostly how to reference the scene to add it to the Player. Any help is greatly appreciated, and the deeper the explanation the better.

Thanks `

you can instantiate the scene and add it to the player on collision:

func _on_body_entered(body):
    var bow_packed = load("path/to/bow_hold.tscn")
    var bow = bow_packed.instantiate()
    body.add_child(bow) # assuming the body is the player
    queue_free()
1 Like

So simple but frustrating when the language is the stopping point, I didn’t even know ‘load’ existed lmao. Thank you so much (:

1 Like