Fix accessing UID before first scan
This commit is contained in:
@ -154,6 +154,19 @@ String ResourceUID::get_id_path(ID p_id) const {
|
||||
ERR_FAIL_COND_V_MSG(p_id == INVALID_ID, String(), "Invalid UID.");
|
||||
MutexLock l(mutex);
|
||||
const ResourceUID::Cache *cache = unique_ids.getptr(p_id);
|
||||
|
||||
#if TOOLS_ENABLED
|
||||
// On startup, the scan_for_uid_on_startup callback should be set and will
|
||||
// execute EditorFileSystem::scan_for_uid, which scans all project files
|
||||
// to reload the UID cache before the first scan.
|
||||
// Note: EditorFileSystem::scan_for_uid sets scan_for_uid_on_startup to nullptr
|
||||
// once the first scan_for_uid is complete.
|
||||
if (!cache && scan_for_uid_on_startup) {
|
||||
scan_for_uid_on_startup();
|
||||
cache = unique_ids.getptr(p_id);
|
||||
}
|
||||
#endif
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!cache, String(), vformat("Unrecognized UID: \"%s\".", id_to_text(p_id)));
|
||||
const CharString &cs = cache->cs;
|
||||
return String::utf8(cs.ptr());
|
||||
|
||||
@ -37,6 +37,8 @@
|
||||
|
||||
class FileAccess;
|
||||
|
||||
typedef void (*ResourceUIDScanForUIDOnStartup)();
|
||||
|
||||
class ResourceUID : public Object {
|
||||
GDCLASS(ResourceUID, Object)
|
||||
public:
|
||||
@ -63,6 +65,8 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
inline static ResourceUIDScanForUIDOnStartup scan_for_uid_on_startup = nullptr;
|
||||
|
||||
String id_to_text(ID p_id) const;
|
||||
ID text_to_id(const String &p_text) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user