diff --git a/core/object.h b/core/object.h index fcfc9f02d07..8630c713b3c 100644 --- a/core/object.h +++ b/core/object.h @@ -91,6 +91,8 @@ enum PropertyUsageFlags { PROPERTY_USAGE_STORE_IF_NULL = 16384, PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768, + PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE = 1 << 17, + PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK, PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED, PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK, diff --git a/core/script_language.cpp b/core/script_language.cpp index c196f6bd179..e128def8128 100644 --- a/core/script_language.cpp +++ b/core/script_language.cpp @@ -277,8 +277,23 @@ ScriptDebugger::ScriptDebugger() { bool PlaceHolderScriptInstance::set(const StringName &p_name, const Variant &p_value) { if (values.has(p_name)) { + Variant defval; + if (script->get_property_default_value(p_name, defval)) { + if (defval == p_value) { + values.erase(p_name); + return true; + } + } values[p_name] = p_value; return true; + } else { + Variant defval; + if (script->get_property_default_value(p_name, defval)) { + if (defval != p_value) { + values[p_name] = p_value; + } + return true; + } } return false; } @@ -288,12 +303,22 @@ bool PlaceHolderScriptInstance::get(const StringName &p_name, Variant &r_ret) co r_ret = values[p_name]; return true; } + + Variant defval; + if (script->get_property_default_value(p_name, defval)) { + r_ret = defval; + return true; + } return false; } void PlaceHolderScriptInstance::get_property_list(List *p_properties) const { for (const List::Element *E = properties.front(); E; E = E->next()) { + PropertyInfo pinfo = E->get(); + if (!values.has(pinfo.name)) { + pinfo.usage |= PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE; + } p_properties->push_back(E->get()); } } @@ -333,6 +358,14 @@ void PlaceHolderScriptInstance::update(const List &p_properties, c if (!new_values.has(E->key())) to_remove.push_back(E->key()); + + Variant defval; + if (script->get_property_default_value(E->key(), defval)) { + //remove because it's the same as the default value + if (defval == E->get()) { + to_remove.push_back(E->key()); + } + } } while (to_remove.size()) { diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 68dc5562d4a..edc0103886f 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -474,6 +474,9 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map bool isdefault = ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one()); + if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) { + isdefault = true; //is script default value + } // if (nd.instance<0 && ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one())) { // continue; // } diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 433cb6621c6..cac30f47d1a 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -188,6 +188,7 @@ void ImageTexture::create(int p_width, int p_height, Image::Format p_format, uin } void ImageTexture::create_from_image(const Image &p_image, uint32_t p_flags) { + ERR_FAIL_COND(p_image.empty()); flags = p_flags; w = p_image.get_width(); h = p_image.get_height();