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

Convert Nodepath properties to Object if "node_type" property hint has been set #83006

Closed
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
19 changes: 17 additions & 2 deletions scene/property_utils.cpp
Original file line number Diff line number Diff line change
@@ -73,16 +73,31 @@ Variant PropertyUtils::get_property_default_value(const Object *p_object, const
for (int i = 0; i < states_stack.size(); ++i) {
const SceneState::PackState &ia = states_stack[i];
bool found = false;
Variant value_in_ancestor = ia.state->get_property_value(ia.node, p_property, found);
bool is_path_node = false;
Variant value_in_ancestor = ia.state->get_property_value(ia.node, p_property, found, is_path_node);
if (found) {
if (r_is_valid) {
*r_is_valid = true;
}

if (is_path_node) {
if (value_in_ancestor.get_type() == Variant::ARRAY) {
Array arr = value_in_ancestor;
for (int j = 0; j < arr.size(); j++) {
if (arr[j].get_type() == Variant::NODE_PATH) {
arr[j] = node->get_node(arr[j]);
}
}
value_in_ancestor = arr;
} else {
value_in_ancestor = node->get_node(value_in_ancestor);
}
}
return value_in_ancestor;
}
// Save script for later
bool has_script = false;
Variant script = ia.state->get_property_value(ia.node, SNAME("script"), has_script);
Variant script = ia.state->get_property_value(ia.node, SNAME("script"), has_script, is_path_node);
if (has_script) {
Ref<Script> scr = script;
if (scr.is_valid()) {
8 changes: 6 additions & 2 deletions scene/resources/packed_scene.cpp
Original file line number Diff line number Diff line change
@@ -1233,8 +1233,9 @@ int SceneState::_find_base_scene_node_remap_key(int p_idx) const {
return -1;
}

Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found) const {
Variant SceneState::get_property_value(int p_node, const StringName &p_property, bool &found, bool &is_path_node) const {
found = false;
is_path_node = false;

ERR_FAIL_COND_V(p_node < 0, Variant());

@@ -1246,6 +1247,9 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property,
const NodeData::Property *p = nodes[p_node].properties.ptr();
for (int i = 0; i < pc; i++) {
if (p_property == namep[p[i].name & FLAG_PROP_NAME_MASK]) {
if (p[i].name & FLAG_PATH_PROPERTY_IS_NODE) {
is_path_node = true;
}
found = true;
return variants[p[i].value];
}
@@ -1255,7 +1259,7 @@ Variant SceneState::get_property_value(int p_node, const StringName &p_property,
//property not found, try on instance

if (base_scene_node_remap.has(p_node)) {
return get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found);
return get_base_scene_state()->get_property_value(base_scene_node_remap[p_node], p_property, found, is_path_node);
}

return Variant();
2 changes: 1 addition & 1 deletion scene/resources/packed_scene.h
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ class SceneState : public RefCounted {
static Ref<Resource> get_remap_resource(const Ref<Resource> &p_resource, HashMap<Ref<Resource>, Ref<Resource>> &remap_cache, const Ref<Resource> &p_fallback, Node *p_for_scene);

int find_node_by_path(const NodePath &p_node) const;
Variant get_property_value(int p_node, const StringName &p_property, bool &found) const;
Variant get_property_value(int p_node, const StringName &p_property, bool &found, bool &is_path_node) const;
bool is_node_in_group(int p_node, const StringName &p_group) const;
bool is_connection(int p_node, const StringName &p_signal, int p_to_node, const StringName &p_to_method) const;