Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait until _ready function to init previous_position to prevent errors #1042

Merged

Conversation

chrisl8
Copy link
Contributor

@chrisl8 chrisl8 commented Apr 10, 2024

Upon starting the project and selecting a truck, this error is always emitted:

E 0:00:22:0996   follow_camera.gd:27 @ @implicit_new(): Condition "!is_inside_tree()" is true. Returning: Transform3D()
  <C++ Source>   scene\3d\node_3d.cpp:346 @ Node3D::get_global_transform()
  <Stack Trace>  follow_camera.gd:27 @ @implicit_new()
                 car_select.gd:15 @ _load_scene()
                 car_select.gd:39 @ _on_mini_van_pressed()

This also happens if you go back and pick a different truck.

I believe this is caused by attempting to assign global_position to a variable before the scene has initialized.

Waiting until the _ready() function to assign the variable for the first time appears to solve this issue.

Other fixes I tried fixed the initial error, but the error persisted if you went "Back" and selected a different truck. This fix covers that case too.

…ors.

Upon starting the project and selecting a truck, this error is always emitted:

```
E 0:00:22:0996   follow_camera.gd:27 @ @implicit_new(): Condition "!is_inside_tree()" is true. Returning: Transform3D()
  <C++ Source>   scene\3d\node_3d.cpp:346 @ Node3D::get_global_transform()
  <Stack Trace>  follow_camera.gd:27 @ @implicit_new()
                 car_select.gd:15 @ _load_scene()
                 car_select.gd:39 @ _on_mini_van_pressed()
```

I believe this is caused by attempting to assign `global_position` to a variable before the scene has initialized.

Waiting until the `_ready()` function to assing the variable for the first time appears to solve this issue.
@AThousandShips
Copy link
Member

@onready doesn't help?

@chrisl8
Copy link
Contributor Author

chrisl8 commented Apr 11, 2024

@AThousandShips @onready prevents the error the first time a truck is selected, but if I use the "Back" button (upper left corner" and select a different truck, the error still happens then on each subsequent truck selection.

@chrisl8
Copy link
Contributor Author

chrisl8 commented Apr 11, 2024

Never mind, I should have re-tested before replying. I'm sure that was the case yesterday, but today @onready fixes it entirely. I will do that instead.

Copy link
Member

@aaronfranke aaronfranke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, the old code is wrong.

@aaronfranke aaronfranke merged commit f70868c into godotengine:master Apr 12, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants