Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose set_uid() #87714

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ Error ResourceSaver::save(const Ref<Resource> &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<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) {
ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object.");
List<String> exts;
Expand All @@ -177,6 +181,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);
Expand Down
1 change: 1 addition & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class ResourceSaver : public Object {
static ResourceSaver *get_singleton() { return singleton; }

Error save(const Ref<Resource> &p_resource, const String &p_path, BitField<SaverFlags> p_flags);
Error set_uid(const String &p_path, ResourceUID::ID p_uid);
Vector<String> get_recognized_extensions(const Ref<Resource> &p_resource);
void add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front);
void remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver);
Expand Down
9 changes: 9 additions & 0 deletions doc/classes/ResourceSaver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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.
</description>
</method>
<method name="set_uid">
<return type="int" enum="Error" />
<param index="0" name="resource" type="String" />
<param index="1" name="uid" type="int" />
<description>
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.
</description>
</method>
</methods>
<constants>
<constant name="FLAG_NONE" value="0" enum="SaverFlags" is_bitfield="true">
Expand Down
Loading