Reparent disable on_area_exit detection ?

Godot Version

Godot 4.6.3

Question

Hi !
I’ve been using Godot for a while now, but I’m having a problem I don’t understand.
Either I’ve missed something or it’s a bug in my version…

My case:

I have this

What I want :

  • when the player enter in the area he became child of Platform
  • when the player exit the are it became a child of the root node

the code

What is does:
Case 1 player start outside of the area

  • the player entrer in area and became child of Plateform

  • the player exit of the area and the player stay child of Plateform (the exit is not print)

Case 2 player start inside of the area

  • the player exit of the area and the player became child of rootNode

  • the player entrer in area and became child of Plateform

  • the player exit of the area and the player stay child of Plateform (the exit is not print)

Case 3 player start outside or inside of the area and only log are in the code(no reparent):

  • all detection are detected enter and exit (the enter and exit are print)

Do you have any idea why this is happening?

Thanks

Does it print enter and exit properly?

Please format your code correctly following the guidelines in this post:

Otherwise we have to re-typed your code to edit it.


The problem is likely that the body exit call is never getting triggered. In which case, the problem is that your Player is part of the platform object and is no longer being detected as a separate body anymore.

Personally, I’d recommend not reparenting the Player. Then tell us why you are doing that - what problem does it solve? And let’s find a solution to that problem. Because fixing the problem you have now is going to be complicated and hacky.

Sorry for the code. This is the code

```gd
extends Node3D
@export var rootnode:Node3D



func _on_area_3d_body_entered(body: Node3D) -> void:
	body.reparent(self)
	print("enter")


func _on_area_3d_body_exited(body: Node3D) -> void:
	body.reparent(rootnode)
	print("exit")

```

For re-parenting the player is for making movable platfrom that stick player or entity on it. (it can be use for ship, car and all movable thing)
It is the easy way to do this is using the graph-scene approach. It’s work well in Unity, Unreal engine and all graph-scene base app.

I think most of your problems arise from the fact you’re reparenting player, i think reparenting is one of the worst thing in game dev cuz you’re changing internal structure

I’d propose you assign player variable to platform, or platform variable to player, and then assign player to this variable as he leaves, enters the area

For the case where player spawns inside area, you may run querry to detect all areas & bodies inside your platform’s area and check if they’re player (maybe add group to them or tag them smh) and if player is inside, add him to the variable

To make a movable platform it would be better to use an AnimatableBody3D instead of a simple Node3D.

A quick search for a tutorial (although in 2D, but 3D works similar) found

Sorry for the small amount of details…
The platform is not a body but an scene witch contain a body and the detection area is a child of the platform.
here the screen capture of scene after the reparent of the player. The platform is a simple Node3D parent of the all system. so the player is not in the body but it is a sibling.

I don’t understand why it does not work in this case. And if I put the player on the platform at start it work only one time.
maybe it is not the good way to do this but it work in all scan graph tool I have use before. So I think I have miss something
By the way thanks for your answer !

Probably your problem would already be fixed if you just changed the type of platform2#StaticBo... to AnimatableBody3D - without ever reparenting the Player.

The problem is not the animation of my platform.
I prefer use an other way to do this with node to control the position. I have a very good level in software programming (My job is tool programming) and I prefer use code to make useful tools for quick development. But thank I will take a look to see if AnimatedBody is better or not has static body.
But in my case the problem is probably in the way I have done my scene graph

I have made a test it is not perfect but maybe with an other scene graph and some movement adjustment it will work.
Thanks !
I let you know if it work or not

Any errors reported in the debugger when reparenting fails?

Try calling reparent() deferred.

Nope no error…
For this case moving the animatedBody Node do the work. So thanks.

But I don’t understand why my solution is not working…
May be I will find later but for now it is solve

Thank for your help

If it’s scene, just use it’s signal with player, it’s still possible