| 1000 | } |
| 1001 | |
| 1002 | void Object::set_script(const Variant &p_script) { |
| 1003 | if (script == p_script) { |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | Ref<Script> s = p_script; |
| 1008 | if (!p_script.is_null()) { |
| 1009 | ERR_FAIL_COND_MSG(s.is_null(), "Cannot set object script. Parameter should be null or a reference to a valid script."); |
| 1010 | ERR_FAIL_COND_MSG(s->is_abstract(), vformat("Cannot set object script. Script '%s' should not be abstract.", s->get_path())); |
| 1011 | } |
| 1012 | |
| 1013 | script = p_script; |
| 1014 | |
| 1015 | if (script_instance) { |
| 1016 | memdelete(script_instance); |
| 1017 | script_instance = nullptr; |
| 1018 | } |
| 1019 | |
| 1020 | if (s.is_valid()) { |
| 1021 | if (s->can_instantiate()) { |
| 1022 | OBJ_DEBUG_LOCK |
| 1023 | script_instance = s->instance_create(this); |
| 1024 | } else if (Engine::get_singleton()->is_editor_hint()) { |
| 1025 | OBJ_DEBUG_LOCK |
| 1026 | script_instance = s->placeholder_instance_create(this); |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | notify_property_list_changed(); |
| 1031 | emit_signal(CoreStringName(script_changed)); |
| 1032 | } |
| 1033 | |
| 1034 | void Object::set_script_instance(ScriptInstance *p_instance) { |
| 1035 | if (script_instance == p_instance) { |
no test coverage detected