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

@export PackedScene scene corruption #80981

Open
Tracked by #80877
SeanRamey opened this issue Aug 25, 2023 · 5 comments
Open
Tracked by #80877

@export PackedScene scene corruption #80981

SeanRamey opened this issue Aug 25, 2023 · 5 comments

Comments

@SeanRamey
Copy link

Godot version

v4.1.1.stable.arch_linux

System information

Godot v4.1.1.stable unknown - EndeavourOS #1 SMP PREEMPT_DYNAMIC Wed, 19 Jul 2023 19:19:38 +0000 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 535.86.05) - Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (6 Threads)

Issue description

When you have an attached script that does @export var other_scene: PackedScene and you use this script on at least two scenes, then you set the PackedScene for each, in the editor, to point to each other (so it would make a circular reference kind-of), one of them will be null on runtime, and if you save it like this and reload the project, the scenes will become corrupted.

Steps to reproduce

  1. Set up a scene with a Node2D as root.
  2. Add a Timer that is set to autostart.
  3. Attach a script to the root Node2D and fill the contents with:
extends Node2D

@export var other_scene: PackedScene = null

func _ready():
	print("scene _ready()")
	if other_scene:
		$Timer.start()
	else:
		print("other_scene was null")


func _on_timer_timeout():
	get_tree().change_scene_to_packed(other_scene)
  1. Connect the timeout signal of the Timer to the _on_timer_timeout() function.
  2. Duplicate this scene and save it as something else.
  3. Edit root node's exported PackedScene property to reference the duplicated scene.
  4. Edit the duplicated scene and also edit it's root node to reference the original scene.
  5. Run and watch as it loads the duplicated scene, but prints
scene _ready()
scene _ready()
other_scene was null

after the duplicated scene is loaded.

Minimal reproduction project

This is the project just before completing Step 7. Completing Step 7 will cause the scenes to become corrupted and you can no longer open the scenes, so you must do Step 7 to see the bug.
ExportPackedSceneBug.zip

@jotson
Copy link
Contributor

jotson commented Sep 25, 2023

I was seeing the same symptom but I didn't have cyclic references. It seems to be something fundamental about @exporting packedscenes.

@mikatomik
Copy link

Just experienced this in 4.1.2 unfortunately. Doors have a packed scene export to the room they connect to. Suddenly got an error that one scene was null, then both went corrupt. Super frustrating :(

@Tuckertcs
Copy link

I've had corruption issues with @tool Resource scripts that utilize @export PackedScene as well. For example, having a Monster Resource with an @export PackedScene pointing to a model or Node3D or something.

@Snowcola
Copy link

had this same issue on 4.2.1 had to switch to load/preload in code

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

7 participants