godotengine / godotengine/godot
`NOTIFICATION_PREDELETE`'s timing across nodes when deleting a scene tree branch is off
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Reproducible in 4.2.1.stable
- Not reproducible in 4.1.3.stable
### System information
Godot v4.2.1.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21905.1001) - AMD Ryzen 7 2700X Eight-Core Processor (16 Threads)
### Issue description
## Problem
When the root node of a branch is freed, `NOTIFICATION_PREDELETE` isn't sent in a consistent order to the nodes of the branch.
In a scene that has the following hierarchy:
```
A--
| AA-
| AAA
| AAB
| AB-
| ABA
| ABB
```
If you free `A--` in 4.2.1, notifications will be sent in the following order:
```
A-- NOTIFICATION_PREDELETE
ABB _exit_tree() callback
ABB tree_exiting signal
ABB NOTIFICATION_EXIT_TREE
ABA _exit_tree() callback
ABA tree_exiting signal
ABA NOTIFICATION_EXIT_TREE
AB- _exit_tree() callback
AB- tree_exiting signal
AB- NOTIFICATION_EXIT_TREE
AAB _exit_tree() callback
AAB tree_exiting signal
AAB NOTIFICATION_EXIT_TREE
AAA _exit_tree() callback
AAA tree_exiting signal
AAA NOTIFICATION_EXIT_TREE
AA- _exit_tree() callback
AA- tree_exiting signal
AA- NOTIFICATION_EXIT_TREE
A-- _exit_tree() callback
A-- tree_exiting signal
A-- NOTIFICATION_EXIT_TREE
ABB tree_exited signal
ABA tree_exited signal
AB- tree_exited signal
AAB tree_exited signal
AAA tree_exited signal
AA- tree_exited signal
A-- tree_exited signal
AB- NOTIFICATION_PREDELETE
ABB NOTIFICATION_PREDELETE
ABA NOTIFICATION_PREDELETE
AA- NOTIFICATION_PREDELETE
AAB NOTIFICATION_PREDELETE
AAA NOTIFICATION_PREDELETE
```
- `NOTIFICATION_PREDELETE` is sent to `A--` before `NOTIFICATION_EXIT_TREE`
- `NOTIFICATION_PREDELETE` isn't sent to the children in the same order as the other notifications
Doing the same thing in 4.1.3 results in the following output:
```
ABB _exit_tree() callback
ABB tree_exiting signal
ABB NOTIFICATION_EXIT_TREE
ABA _exit_tree() callback
ABA tree_exiting signal
ABA NOTIFICATION_EXIT_TREE
AB- _exit_tree() callback
AB- tree_exiting signal
AB- NOTIFICATION_EXIT_TREE
AAB _exit_tree() callback
AAB tree_exiting signal
AAB NOTIFICATION_EXIT_TREE
AAA _exit_tree() callback
AAA tree_exiting signal
AAA NOTIFICATION_EXIT_TREE
AA- _exit_tree() callback
AA- tree_exiting signal
AA- NOTIFICATION_EXIT_TREE
A-- _exit_tree() callback
A-- tree_exiting signal
A-- NOTIFICATION_EXIT_TREE
ABB tree_exited signal
ABA tree_exited signal
AB- tree_exited signal
AAB tree_exited signal
AAA tree_exited signal
AA- tree_exited signal
A-- tree_exited signal
ABB NOTIFICATION_PREDELETE
ABA NOTIFICATION_PREDELETE
AB- NOTIFICATION_PREDELETE
AAB NOTIFICATION_PREDELETE
AAA NOTIFICATION_PREDELETE
AA- NOTIFICATION_PREDELETE
A-- NOTIFICATION_PREDELETE
```
In this case there is no problem.
## Expected behavior
I expect the timing of `NOTIFICATION_PREDELETE` to be the same as in 4.1.3.
## Notes
- This issue was first reported in https://github.com/godotengine/godot-docs/issues/5492#issuecomment-1868710598
- I'm using the scene provided by KoBeWi from the issue above
### Steps to reproduce
1. open the MRP and run the current scene
2. the notifications' order will be printed to the output
### Minimal reproduction project (MRP)
[MRP.zip](https://github.com/godotengine/godot/files/13928647/MRP.zip)
Contributor guide
Assessment
This issue has not been assessed yet.