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

create_tween returns null after scene change #85649

Open
davidkbd opened this issue Dec 2, 2023 · 2 comments
Open

create_tween returns null after scene change #85649

davidkbd opened this issue Dec 2, 2023 · 2 comments

Comments

@davidkbd
Copy link

davidkbd commented Dec 2, 2023

Godot version

4.2

System information

Manjaro Linux

Issue description

When calling create_tween() from a method called by call_deferred() immediately after a scene change (e.g. with reload_current_scene), create_tween() returns null.

Steps to reproduce

  1. Create a new Godot project.
  2. Create a scene Node2D with two Area2Ds.
  3. Connect the area_exited signal of one of the Area2Ds to a method called on_area_exited.
  4. Add the following code to the on_area_exited() method:

func _deferred_exited() -> void:
print("Exited ", create_tween())
# If we need use the tween here, a crash is produced.

func on_area_area_exited(_area) -> void:
#_deferred_exited() #<-- this works OK
call_deferred("_deferred_exited") #<-- this create_tween returns null/ in godot 4.1 works OK

  1. Create a button and connect its pressed signal to a method called on_button_pressed().
  2. Add the following code to the on_button_pressed() method:

func _on_button_pressed() -> void:
get_tree().reload_current_scene()

  1. Run the project
  2. Click the button.
  3. Check the output to see the value of tween. It should be null.

Minimal reproduction project

reload_scene_tween_bug.tar.gz

@kleonc
Copy link
Member

kleonc commented Dec 2, 2023

This is caused by the changes in #78988.

The behavior change is mentioned in the Critical and breaking changes section of the 4.2.stable release blog post:

An internal rework of the change_scene_to_* methods introduces a change in behavior compared to Godot 4.1 (GH-78988).

While previously the transition would happen at the end of the current frame, starting with Godot 4.2 the current scene is removed from the tree immediately. This means there is a brief period when no current_scene is present in the tree, so you may need to adjust your scripts to account for that. See the updated documentation for more details.

However, it's not mentioned anywhere that reload_current_scene is also affected.

Error SceneTree::reload_current_scene() {
ERR_FAIL_COND_V_MSG(!Thread::is_main_thread(), ERR_INVALID_PARAMETER, "Reloading scene can only be done from the main thread.");
ERR_FAIL_NULL_V(current_scene, ERR_UNCONFIGURED);
String fname = current_scene->get_scene_file_path();
return change_scene_to_file(fname);
}

The docs of reload_current_scene need to be updated accordingly.

@KoBeWi
Copy link
Member

KoBeWi commented Feb 1, 2024

#87701 fixed the original issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants