Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { RES res = ResourceLoader::load(p_path); ERR_EXPLAIN("Can't autoload: " + p_path); ERR_FAIL_COND_V(res.is_null(), NULL); Node *n = NULL; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; n = ps->instance(); } else if (res->is_class("Script")) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); ERR_EXPLAIN("Script does not inherit a Node: " + p_path); ERR_FAIL_COND_V(!valid_type, NULL); Object *obj = ClassDB::instance(ibt); ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); ERR_FAIL_COND_V(obj == NULL, NULL); n = Object::cast_to<Node>(obj); n->set_script(s.get_ref_ptr()); } ERR_EXPLAIN("Path in autoload not a node or script: " + p_path); ERR_FAIL_COND_V(!n, NULL); return n; }