-
-
Notifications
You must be signed in to change notification settings - Fork 23.4k
Description
Godot version
latest, with #61286 applied
System information
Arch Linux
Issue description
Note
This issue is only relevant with the functionality of #61286 applied
When implementing the functionality to unload PCK files (which involves clearing GDScript cache of the loaded pack to clear scripts; not sure if that's the root cause), reloading such files results in an error where a custom class_name
class that's defined on the main project, works on the main project, but when running code on the loaded pack, Godot complains the class is not from the correct type:
This only occurs when the pack in unloaded; when the pack is loaded for the first time, or is reloaded without unloading it first, this issue doesn't occur.
Steps to reproduce
- Have the main project and sub-project define some custom resource using
class_name
:
extends Resource
class_name MyResource
var text := "default"
extends Control
func got_info(info: MyResource):
$Label.text = info.text
- Export the sub-project as a PCK file.
- In the main project, load the PCK file, instance the scene, then call that method:
func load_pck():
print("Result: ", ProjectSettings.load_resource_pack(pck_file), false)
var child = load("res://scene.tscn").instantiate()
$SubViewportContainer/SubViewport.add_child(child)
var my_res := MyResource.new()
my_res.text = "test"
child.got_info(my_res)
So far so good; there's no issues with reloading this pack file
- Now add functionality on the main project to unload the PCK file before reloading it.
func _on_button_pressed():
await unload_pck()
load_pck()
func unload_pck():
for child in $SubViewportContainer/SubViewport.get_children():
$SubViewportContainer/SubViewport.remove_child(child)
child.queue_free()
while is_instance_valid(child):
await get_tree().process_frame
print("Result: ", ProjectSettings.unload_resource_pack(pck_file))
- Now, when reloading the same scene, the issue will occur when
got_info
is called on the instanced child object.
Some other scenarios I've tested:
- This issue still occurs if the pack is allowed to replace files.
- This issue does not occur if in the
got_info
method, the argument type is not specified:
extends Control
func got_info(info):
$Label.text = info.text
- On Implement unload of PCK files #61286, commenting the part that clears the pack's script cache also stops this issue from occurring. However, it's not a solution since scripts need to be cleared when a pack is unloaded.
https://github.com/godotengine/godot/pull/61286/files#diff-f45df99ed947ca0517c7b926532a8c1a3d27aeda5797c510da673e10462d75cfR191-R195 - When backporting this functionality to 3.x, there are no issues whatsoever. Might be because 3.x didn't have this GDScript caching functionality.
Minimal reproduction project
Note
Needs #61286 applied in order to get the unload pack functionality
This contains two projects: the main project on root, and sub-project on inner
folder. The sub-project is already exported at inner/inner.pck
. Run the main project, and click on the Load button to reload the pack and trigger the issue.