godotengine / godotengine/godot-cpp

get_node() does not work at the start of _ready()

Open
#1,131 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### Godot version

4.0.3.stable.official.5222a99f5

### godot-cpp version

3a9118cb0dafef74773216c47a030c3a4a490747

### System information

Ubuntu 22.10 x86_64

### Issue description

It seems like the ready notification gets sent slightly too early, causing the scene tree to not be instiantiated fully when _ready() is called.

I was trying to rewrite the "Squash the Creeps" tutorial in c++ when I stumbled upon this.
The following code was the problem:
```cpp
void Main::_ready() {
auto retry = get_node("UserInterface/Retry");
retry->hide();
}
```
When I call something like `print_tree()` before `get_node()` it gets the node successfully.

### Steps to reproduce

1. Set up project with godot-cpp
2. add an empty node to the scene
3. add a child to that node
4. create a new class in c++ that uses `get_node()` to get the child in the `_ready()` function
5. change the type of the parent node to the custom class
6. watch godot crash

### Minimal reproduction project

N/A

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.