Merge pull request #68987 from adamscott/fix-godot#61386-autoload-scenes-implicit-types

Fix autoload scenes implicit types
This commit is contained in:
Rémi Verschelde 2022-11-22 08:31:36 +01:00
commit c474e2f639
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 38 additions and 0 deletions

View file

@ -365,6 +365,31 @@ Ref<PackedScene> GDScriptCache::get_packed_scene(const String &p_path, Error &r_
return scene;
}
Ref<GDScript> GDScriptCache::get_packed_scene_script(const String &p_path, Error &r_error) {
r_error = OK;
Ref<PackedScene> scene = get_packed_scene(p_path, r_error);
if (r_error != OK) {
return Ref<GDScript>();
}
int node_count = scene->get_state()->get_node_count();
if (node_count == 0) {
return Ref<GDScript>();
}
const int ROOT_NODE = 0;
for (int i = 0; i < scene->get_state()->get_node_property_count(ROOT_NODE); i++) {
if (scene->get_state()->get_node_property_name(ROOT_NODE, i) != SNAME("script")) {
continue;
}
return scene->get_state()->get_node_property_value(ROOT_NODE, i);
}
return Ref<GDScript>();
}
void GDScriptCache::clear_unreferenced_packed_scenes() {
if (singleton == nullptr) {
return;