Make BBParam properties unique @clone()

This commit is contained in:
Serhii Snitsaruk 2022-10-21 16:15:13 +02:00
parent 54addba8a3
commit d359f620e3
1 changed files with 27 additions and 0 deletions

View File

@ -100,6 +100,33 @@ Ref<BTTask> BTTask::clone() const {
c->parent = inst.ptr();
inst->children.set(i, c);
}
// Make BBParam properties unique.
List<PropertyInfo> props;
inst->get_property_list(&props);
Map<RES, RES> duplicates;
for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
Variant v = inst->get(E->get().name);
if (v.is_ref()) {
REF ref = v;
if (ref.is_valid()) {
RES res = ref;
if (res.is_valid() && res->is_class("BBParam")) {
if (!duplicates.has(res)) {
duplicates[res] = res->duplicate();
}
res = duplicates[res];
inst->set(E->get().name, res);
}
}
}
}
return inst;
}