1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

Fix case where exported properties value is lost

Fixes exported property modified values lost when creating a placeholder script instance with a failed script compilation

- Object set/get will call PlaceHolderScriptInstance's new fallback set/get methods as a last resort. This way, placeholder script instances can keep the values for storage or until the script is compiled successfuly.
- Script::can_instance() will only return true if a real script instance can be created. Otherwise, in the case of placeholder script instances, it will return false.
- Object::set_script(script) is now in charge of requesting the creation of placeholder script instances. It's no longer Script::instance_create(owner)'s duty.
- PlaceHolderScriptInstance has a new method set_build_failed(bool) to determine whether it should call into its script methods or not.
- Fixed a few problems during reloading of C# scripts.
This commit is contained in:
Ignacio Etcheverry
2018-07-29 22:40:09 +02:00
parent 6601502acd
commit f3c7527225
7 changed files with 253 additions and 57 deletions

View File

@@ -450,16 +450,41 @@ void Object::set(const StringName &p_name, const Variant &p_value, bool *r_valid
*r_valid = true;
return;
#endif
} else {
//something inside the object... :|
bool success = _setv(p_name, p_value);
if (success) {
}
//something inside the object... :|
bool success = _setv(p_name, p_value);
if (success) {
if (r_valid)
*r_valid = true;
return;
}
{
bool valid;
setvar(p_name, p_value, &valid);
if (valid) {
if (r_valid)
*r_valid = true;
return;
}
setvar(p_name, p_value, r_valid);
}
#ifdef TOOLS_ENABLED
if (script_instance) {
bool valid;
script_instance->property_set_fallback(p_name, p_value, &valid);
if (valid) {
if (r_valid)
*r_valid = true;
return;
}
}
#endif
if (r_valid)
*r_valid = false;
return;
}
Variant Object::get(const StringName &p_name, bool *r_valid) const {
@@ -513,8 +538,33 @@ Variant Object::get(const StringName &p_name, bool *r_valid) const {
*r_valid = true;
return ret;
}
//if nothing else, use getvar
return getvar(p_name, r_valid);
{
bool valid;
ret = getvar(p_name, &valid);
if (valid) {
if (r_valid)
*r_valid = true;
return ret;
}
}
#ifdef TOOLS_ENABLED
if (script_instance) {
bool valid;
ret = script_instance->property_get_fallback(p_name, &valid);
if (valid) {
if (r_valid)
*r_valid = true;
return ret;
}
}
#endif
if (r_valid)
*r_valid = false;
return Variant();
}
}
@@ -979,9 +1029,14 @@ void Object::set_script(const RefPtr &p_script) {
script = p_script;
Ref<Script> s(script);
if (!s.is_null() && s->can_instance()) {
OBJ_DEBUG_LOCK
script_instance = s->instance_create(this);
if (!s.is_null()) {
if (s->can_instance()) {
OBJ_DEBUG_LOCK
script_instance = s->instance_create(this);
} else if (Engine::get_singleton()->is_editor_hint()) {
OBJ_DEBUG_LOCK
script_instance = s->placeholder_instance_create(this);
}
}
_change_notify("script");