Fix index in loading of Array[Node]
This commit is contained in:
parent
764193629f
commit
bbd4873eea
@ -244,35 +244,11 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
|
|||||||
uint32_t name_idx = nprops[j].name & (FLAG_PATH_PROPERTY_IS_NODE - 1);
|
uint32_t name_idx = nprops[j].name & (FLAG_PATH_PROPERTY_IS_NODE - 1);
|
||||||
ERR_FAIL_UNSIGNED_INDEX_V(name_idx, (uint32_t)sname_count, nullptr);
|
ERR_FAIL_UNSIGNED_INDEX_V(name_idx, (uint32_t)sname_count, nullptr);
|
||||||
|
|
||||||
const StringName &prop_name = snames[name_idx];
|
DeferredNodePathProperties dnp;
|
||||||
const Variant &prop_variant = props[nprops[j].value];
|
dnp.value = props[nprops[j].value];
|
||||||
|
dnp.base = node;
|
||||||
if (prop_variant.get_type() == Variant::ARRAY) {
|
dnp.property = snames[name_idx];
|
||||||
const Array &array = prop_variant;
|
deferred_node_paths.push_back(dnp);
|
||||||
if (Engine::get_singleton()->is_editor_hint()) {
|
|
||||||
if (array.get_typed_builtin() == Variant::NODE_PATH) {
|
|
||||||
// If editor, simply set the original array of NodePaths.
|
|
||||||
node->set(prop_name, prop_variant);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (int k = 0; k < array.size(); k++) {
|
|
||||||
DeferredNodePathProperties dnp;
|
|
||||||
dnp.path = array[k];
|
|
||||||
dnp.base = node;
|
|
||||||
// Use special property name to signify an array. This is only used in deferred_node_paths.
|
|
||||||
dnp.property = String(prop_name) + "/indices/" + itos(k);
|
|
||||||
deferred_node_paths.push_back(dnp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// Do an actual deferred set of the property path.
|
|
||||||
DeferredNodePathProperties dnp;
|
|
||||||
dnp.path = prop_variant;
|
|
||||||
dnp.base = node;
|
|
||||||
dnp.property = prop_name;
|
|
||||||
deferred_node_paths.push_back(dnp);
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,27 +441,21 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const {
|
|||||||
|
|
||||||
for (const DeferredNodePathProperties &dnp : deferred_node_paths) {
|
for (const DeferredNodePathProperties &dnp : deferred_node_paths) {
|
||||||
// Replace properties stored as NodePaths with actual Nodes.
|
// Replace properties stored as NodePaths with actual Nodes.
|
||||||
Node *other = dnp.base->get_node_or_null(dnp.path);
|
if (dnp.value.get_type() == Variant::ARRAY) {
|
||||||
|
Array paths = dnp.value;
|
||||||
const String string_property = dnp.property;
|
|
||||||
if (string_property.contains("/indices/")) {
|
|
||||||
// For properties with "/indices/", the replacement takes place inside an Array.
|
|
||||||
const String base_property = string_property.get_slice("/", 0);
|
|
||||||
const int index = string_property.get_slice("/", 2).to_int();
|
|
||||||
|
|
||||||
bool valid;
|
bool valid;
|
||||||
Array array = dnp.base->get(base_property, &valid);
|
Array array = dnp.base->get(dnp.property, &valid);
|
||||||
ERR_CONTINUE(!valid);
|
ERR_CONTINUE(!valid);
|
||||||
|
array = array.duplicate();
|
||||||
|
|
||||||
if (array.size() >= index) {
|
array.resize(paths.size());
|
||||||
array.push_back(other);
|
for (int i = 0; i < array.size(); i++) {
|
||||||
} else {
|
array.set(i, dnp.base->get_node_or_null(paths[i]));
|
||||||
array.set(index, other);
|
|
||||||
}
|
}
|
||||||
|
dnp.base->set(dnp.property, array);
|
||||||
dnp.base->set(base_property, array);
|
|
||||||
} else {
|
} else {
|
||||||
dnp.base->set(dnp.property, other);
|
dnp.base->set(dnp.property, dnp.base->get_node_or_null(dnp.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ class SceneState : public RefCounted {
|
|||||||
struct DeferredNodePathProperties {
|
struct DeferredNodePathProperties {
|
||||||
Node *base = nullptr;
|
Node *base = nullptr;
|
||||||
StringName property;
|
StringName property;
|
||||||
NodePath path;
|
Variant value;
|
||||||
};
|
};
|
||||||
|
|
||||||
Vector<NodeData> nodes;
|
Vector<NodeData> nodes;
|
||||||
|
Loading…
Reference in New Issue
Block a user