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

Godot 3.5 : Error when switching between inherited scenes #29

Open
BasileAltar opened this issue Aug 29, 2023 · 3 comments
Open

Godot 3.5 : Error when switching between inherited scenes #29

BasileAltar opened this issue Aug 29, 2023 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@BasileAltar
Copy link

Describe the bug
Please note that I am still on Godot 3.5 until my project is over. I do not expect a bug correction on this version, but rather a quick workaround if you know any.

When calling change_scene() between two inherited scenes, the scene replacement works as intended, but an error is shown in the debugger :
image

The error is on the instruction _root.add_child() :
image

Every time I call change_scene, the same error is repeated, but again the scene replacement works as intended.

To Reproduce
On Godot 3.5

  1. Have two Node2D scenes.
  2. Create an inherited scene from each scene (scene -> new inherited scene)
  3. Attach a script to a child scene, then call change_scene from the scene to the other child scene
  4. The scene replacement works as intended, but an error appears in the stacktrace.
  5. Call change_scene multiple times to get multiple errors.
  6. The error does not appear when calling change_scene between non-inherited scenes.

Expected behavior
The scene switch should happen with no error.
I would either like to solve the error, or to know if I can safely keep it.

Screenshots
The code to change scene (event fired from a Node2D collision)
image

The target inherited scene
image

The base scene
image

Desktop

  • Windows 10

Additional context
Godot 3.5

@Villagerjj
Copy link

this bug is also present in godot 4.2.2, I am going to do some investigating

@Villagerjj
Copy link

Villagerjj commented Jul 8, 2024

UPDATE:
this "fixes" the issue, only for the first scene transition in your game, any other attempts fail, use at your own risk!

I replace the code in the _replace_scene function with this code:

	_current_scene.queue_free()
	scene_unloaded.emit()
	var following_scene: PackedScene = ResourceLoader.load(path, "PackedScene", 0)
	var temp_current_scene = following_scene.instantiate()
	_current_scene = temp_current_scene
	_current_scene.tree_entered.connect(options["on_tree_enter"].bind(_current_scene))
	_current_scene.ready.connect(options["on_ready"].bind(_current_scene))
	await _tree.create_timer(0.0).timeout
	_root.add_child(temp_current_scene)
	_tree.set_current_scene(_current_scene)

this seems to keep all the logic in order

@jabsatz jabsatz added bug Something isn't working good first issue Good for newcomers labels Nov 22, 2024
@jabsatz
Copy link
Collaborator

jabsatz commented Nov 22, 2024

Hello, thanks for the report and the fix (and sorry for the late reply). Does your fix work correctly or did you run into any further issues? We might just add that code directly into the 3.x branch in that case, if you'd like to do it PRs are also welcome here!

I just made a blog post here explaining the situation of this plugin #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants