@@ -2065,9 +2065,13 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
20652065
20662066 List<PropertyInfo> property_list;
20672067
2068- res->get_property_list (&property_list);
2068+ // In EditorFileSystem, it might be assumed that the first dependency is `script`.
2069+ // Iterate in reverse to ensure the script is the first external resource.
2070+ res->get_property_list (&property_list, true );
2071+ List<PropertyInfo>::Element *I = property_list.back ();
20692072
2070- for (const PropertyInfo &E : property_list) {
2073+ while (I) {
2074+ const PropertyInfo &E = I->get ();
20712075 if (E.usage & PROPERTY_USAGE_STORAGE) {
20722076 Variant value = res->get (E.name );
20732077 if (E.usage & PROPERTY_USAGE_RESOURCE_NOT_PERSISTENT) {
@@ -2087,6 +2091,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant
20872091 _find_resources (value);
20882092 }
20892093 }
2094+ I = I->prev ();
20902095 }
20912096
20922097 saved_resources.push_back (res);
@@ -2402,7 +2407,7 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const Ref<Re
24022407 return OK;
24032408}
24042409
2405- Error ResourceFormatSaverBinaryInstance::set_uid (const String &p_path, ResourceUID::ID p_uid) {
2410+ Error ResourceFormatSaverBinaryInstance::set_info (const String &p_path, ResourceUID::ID p_uid, const String &p_script_class ) {
24062411 Ref<FileAccess> f = FileAccess::open (p_path, FileAccess::READ);
24072412 ERR_FAIL_COND_V_MSG (f.is_null (), ERR_CANT_OPEN, vformat (" Cannot open file '%s'." , p_path));
24082413
@@ -2483,13 +2488,26 @@ Error ResourceFormatSaverBinaryInstance::set_uid(const String &p_path, ResourceU
24832488
24842489 uint32_t flags = f->get_32 ();
24852490 flags |= ResourceFormatSaverBinaryInstance::FORMAT_FLAG_UIDS;
2486- f->get_64 (); // Skip previous UID
2491+
2492+ if (p_uid == ResourceUID::INVALID_ID) {
2493+ p_uid = ResourceUID::ID (f->get_64 ()); // Keep previous UID
2494+ } else {
2495+ f->get_64 (); // Skip previous UID
2496+ }
2497+
2498+ if (!p_script_class.is_empty ()) {
2499+ flags |= ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS;
2500+ }
24872501
24882502 fw->store_32 (flags);
24892503 fw->store_64 (uint64_t (p_uid));
24902504
24912505 if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
2492- save_ustring (fw, get_ustring (f));
2506+ String script_class = get_ustring (f);
2507+ if (!p_script_class.is_empty ()) {
2508+ script_class = p_script_class;
2509+ }
2510+ save_ustring (fw, script_class);
24932511 }
24942512
24952513 // rest of file
@@ -2524,7 +2542,13 @@ Error ResourceFormatSaverBinary::save(const Ref<Resource> &p_resource, const Str
25242542Error ResourceFormatSaverBinary::set_uid (const String &p_path, ResourceUID::ID p_uid) {
25252543 String local_path = ProjectSettings::get_singleton ()->localize_path (p_path);
25262544 ResourceFormatSaverBinaryInstance saver;
2527- return saver.set_uid (local_path, p_uid);
2545+ return saver.set_info (local_path, p_uid, String ());
2546+ }
2547+
2548+ Error ResourceFormatSaverBinary::set_script_class (const String &p_path, const String &p_script_class) {
2549+ String local_path = ProjectSettings::get_singleton ()->localize_path (p_path);
2550+ ResourceFormatSaverBinaryInstance saver;
2551+ return saver.set_info (p_path, ResourceUID::INVALID_ID, p_script_class);
25282552}
25292553
25302554bool ResourceFormatSaverBinary::recognize (const Ref<Resource> &p_resource) const {
0 commit comments