Adding self as child to another object

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

Trying to start an inventory system, and get an object to add itself as a child to another object when picked up by the player, but body.add_child(self) doesn’t seem to work. I don’t get any errors but nothing happens.

func trigger_body_entered(body):
if body.has_method("pickUp_Weapon"):
	if body.weapons[1] == "Empty":
		print ("Picked up " + weaponName)
		body.weapons[1] = weaponName
		pickUp = false
		print ("Already have " + weaponName)
:bust_in_silhouette: Reply From: andersmmg

I don’t think you can change the parent of an item. You can either create a new instance of itself and add that as a child, or have the weapon follow a point when a “holding” variable is true or something. I’d recommend the first option.

Ok thank you

Sir_Skurpsalot | 2019-08-17 04:40