MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / set_script

Method set_script

core/object/object.cpp:1002–1032  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1000}
1001
1002void 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
1034void Object::set_script_instance(ScriptInstance *p_instance) {
1035 if (script_instance == p_instance) {

Callers 4

_to_nativeMethod · 0.45
decode_variantFunction · 0.45

Calls 10

vformatFunction · 0.85
memdeleteFunction · 0.85
is_nullMethod · 0.45
is_abstractMethod · 0.45
get_pathMethod · 0.45
is_validMethod · 0.45
can_instantiateMethod · 0.45
instance_createMethod · 0.45
is_editor_hintMethod · 0.45

Tested by

no test coverage detected