#Changing parent of instanced object

8 messages · Page 1 of 1 (latest)

red lava
#

I am working on a game that has instanced objects spawning rigidbody3D(eggs) from a node3D(nest_manager), after it spawns 5 eggs and groups them in "eggs". I want the player to be able to pick up the egg from the nest and hold it over their head as they run around before depositing it in a bin. I have an Area3d and collisionshape3d to detect when the player is within range on the eggs and then the player can "use" to get a single egg.

The problem is arising when I'm removing the parent from the egg and trying to add it as the player's child I keep getting a hard crash with player.gd: @ pick_up_egg(): can't add child 'player' to itself. As well as Condition '!is_inside_tree()' is true. returning: Transform3D().

I don't see any recursive code, but I'm very new to this.

My game is set up as a node(main) with both the nest_manager and player instantiated into it. is it something that I should have just made them as children of main? instead of their own scenes?

I've included the bulk of the pickup code where the error is getting called out.
Any help is appreciated or if you have ideas on an easier way to do this I'm all ears!

supple rune
#

Try replacing both the egg.get_parent().remove_child(egg) and the self.add_child(egg) with egg.reparent(self)

red lava
#

while I like that it's simplified my code, unfortunately it gives the same errors as before

hot yoke
#

The code seems fine to me. It could be that the EggPickupArea is colliding with the player to. So try to give the player a different collision layer. And dont look for it in the area.
If you're already doing so, than idk whats wrong 🙂

red lava
#

That's a great idea, I didn't think about that!

hot yoke
#

Ok, than it should fix it

red lava
#

it absolutely did!! Thank you so much! I was banging my head against the keyboard all day yesterday! you're the best! by chance do you know how I make this as solved?

#

NM/Got it! thanks again!!!