Skip to content

Commit 67b95f3

Browse files
committed
Fix UID support in MultiplayerSpawner
1 parent bbc5469 commit 67b95f3

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

core/io/resource_uid.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ String ResourceUID::uid_to_path(const String &p_uid) {
145145
}
146146

147147
String ResourceUID::path_to_uid(const String &p_path) {
148-
return singleton->id_to_text(ResourceLoader::get_resource_uid(p_path));
148+
const ID id = ResourceLoader::get_resource_uid(p_path);
149+
if (id == INVALID_ID) {
150+
return p_path;
151+
} else {
152+
return singleton->id_to_text(id);
153+
}
149154
}
150155

151156
String ResourceUID::ensure_path(const String &p_uid_or_path) {

modules/multiplayer/multiplayer_spawner.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool MultiplayerSpawner::_set(const StringName &p_name, const Variant &p_value)
4646
if (ns.begins_with("scenes/")) {
4747
uint32_t index = ns.get_slicec('/', 1).to_int();
4848
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
49-
spawnable_scenes[index].path = p_value;
49+
spawnable_scenes[index].path = ResourceUID::ensure_path(p_value);
5050
return true;
5151
}
5252
}
@@ -62,7 +62,7 @@ bool MultiplayerSpawner::_get(const StringName &p_name, Variant &r_ret) const {
6262
if (ns.begins_with("scenes/")) {
6363
uint32_t index = ns.get_slicec('/', 1).to_int();
6464
ERR_FAIL_UNSIGNED_INDEX_V(index, spawnable_scenes.size(), false);
65-
r_ret = spawnable_scenes[index].path;
65+
r_ret = ResourceUID::path_to_uid(spawnable_scenes[index].path);
6666
return true;
6767
}
6868
}
@@ -97,15 +97,9 @@ PackedStringArray MultiplayerSpawner::get_configuration_warnings() const {
9797

9898
void MultiplayerSpawner::add_spawnable_scene(const String &p_path) {
9999
SpawnableScene sc;
100-
if (p_path.begins_with("uid://")) {
101-
sc.uid = p_path;
102-
sc.path = ResourceUID::uid_to_path(p_path);
103-
} else {
104-
sc.uid = ResourceUID::path_to_uid(p_path);
105-
sc.path = p_path;
106-
}
100+
sc.path = ResourceUID::ensure_path(p_path);
107101
if (Engine::get_singleton()->is_editor_hint()) {
108-
ERR_FAIL_COND(!ResourceLoader::exists(p_path));
102+
ERR_FAIL_COND(!ResourceLoader::exists(sc.path));
109103
}
110104
spawnable_scenes.push_back(sc);
111105
#ifdef TOOLS_ENABLED
@@ -145,7 +139,7 @@ Vector<String> MultiplayerSpawner::_get_spawnable_scenes() const {
145139
Vector<String> ss;
146140
ss.resize(spawnable_scenes.size());
147141
for (int i = 0; i < ss.size(); i++) {
148-
ss.write[i] = spawnable_scenes[i].uid;
142+
ss.write[i] = ResourceUID::path_to_uid(spawnable_scenes[i].path);
149143
}
150144
return ss;
151145
}

modules/multiplayer/multiplayer_spawner.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class MultiplayerSpawner : public Node {
4949
private:
5050
struct SpawnableScene {
5151
String path;
52-
String uid;
5352
Ref<PackedScene> cache;
5453
};
5554

0 commit comments

Comments
 (0)