From 6f4cf04fb8a160643d27799ede869a9242fc892d Mon Sep 17 00:00:00 2001 From: kobewi Date: Mon, 29 Jan 2024 21:25:20 +0100 Subject: [PATCH] Expose set_uid() --- core/core_bind.cpp | 5 +++++ core/core_bind.h | 1 + doc/classes/ResourceSaver.xml | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 2b1b5f094b..ae7708074e 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -169,6 +169,10 @@ Error ResourceSaver::save(const Ref &p_resource, const String &p_path, return ::ResourceSaver::save(p_resource, p_path, p_flags); } +Error ResourceSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) { + return ::ResourceSaver::set_uid(p_path, p_uid); +} + Vector ResourceSaver::get_recognized_extensions(const Ref &p_resource) { List exts; ::ResourceSaver::get_recognized_extensions(p_resource, &exts); @@ -195,6 +199,7 @@ ResourceSaver *ResourceSaver::singleton = nullptr; void ResourceSaver::_bind_methods() { ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE)); + ClassDB::bind_method(D_METHOD("set_uid", "resource", "uid"), &ResourceSaver::set_uid); ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions); ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false)); ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver); diff --git a/core/core_bind.h b/core/core_bind.h index 5f8f3165a6..04f1183aa6 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -110,6 +110,7 @@ public: static ResourceSaver *get_singleton() { return singleton; } Error save(const Ref &p_resource, const String &p_path, BitField p_flags); + Error set_uid(const String &p_path, ResourceUID::ID p_uid); Vector get_recognized_extensions(const Ref &p_resource); void add_resource_format_saver(Ref p_format_saver, bool p_at_front); void remove_resource_format_saver(Ref p_format_saver); diff --git a/doc/classes/ResourceSaver.xml b/doc/classes/ResourceSaver.xml index 05c749bc24..92ab5efeb2 100644 --- a/doc/classes/ResourceSaver.xml +++ b/doc/classes/ResourceSaver.xml @@ -53,6 +53,15 @@ [b]Note:[/b] When the project is running, any generated UID associated with the resource will not be saved as the required code is only executed in editor mode. + + + + + + Sets the UID of the given [param resource] path to [param uid]. You can generate a new UID using [method ResourceUID.create_id]. + Since resources will normally get a UID automatically, this method is only useful in very specific cases. + +