Skip to content

Commit

Permalink
Fixes inability to assign script after clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
anvilfolk committed Nov 22, 2022
1 parent 98da707 commit 9187f5c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 4 additions & 2 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_v
if (values.has(p_name)) {
Variant defval;
if (script->get_property_default_value(p_name, defval)) {
if (defval == p_value) {
// The evaluate function ensures that a NIL variant is equal to e.g. an empty Resource.
// Simply doing defval == p_value does not do this.
if (Variant::evaluate(Variant::OP_EQUAL, defval, p_value)) {
values.erase(p_name);
return true;
}
Expand All @@ -419,7 +421,7 @@ bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_v
} else {
Variant defval;
if (script->get_property_default_value(p_name, defval)) {
if (defval != p_value) {
if (Variant::evaluate(Variant::OP_NOT_EQUAL, defval, p_value)) {
values[p_name] = p_value;
}
return true;
Expand Down
6 changes: 5 additions & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "editor_properties.h"

#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_node.h"
#include "editor/editor_properties_array_dict.h"
Expand Down Expand Up @@ -3844,8 +3845,11 @@ void EditorPropertyResource::_resource_selected(const Ref<Resource> &p_resource,
void EditorPropertyResource::_resource_changed(const Ref<Resource> &p_resource) {
// Make visual script the correct type.
Ref<Script> s = p_resource;

// The bool is_script applies only to an object's main script.
// Changing the value of Script-type exported variables of the main script should not trigger saving/reloading properties.
bool is_script = false;
if (get_edited_object() && s.is_valid()) {
if (get_edited_object() && s.is_valid() && get_edited_property() == CoreStringNames::get_singleton()->_script) {
is_script = true;
InspectorDock::get_singleton()->store_script_properties(get_edited_object());
s->call("set_instance_base_type", get_edited_object()->get_class());
Expand Down

0 comments on commit 9187f5c

Please sign in to comment.