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

Method create_instance

scene/main/instance_placeholder.cpp:81–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

79}
80
81Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene> &p_custom_scene) {
82 ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
83
84 Node *base = get_parent();
85 if (!base) {
86 return nullptr;
87 }
88
89 Ref<PackedScene> ps;
90 if (p_custom_scene.is_valid()) {
91 ps = p_custom_scene;
92 } else {
93 ps = ResourceLoader::load(path, "PackedScene");
94 }
95
96 if (ps.is_null()) {
97 return nullptr;
98 }
99 Node *instance = ps->instantiate();
100 if (!instance) {
101 return nullptr;
102 }
103 instance->set_name(get_name());
104 instance->set_multiplayer_authority(get_multiplayer_authority());
105 int pos = get_index();
106
107 for (const PropSet &E : stored_values) {
108 set_value_on_instance(this, instance, E);
109 }
110
111 if (p_replace) {
112 queue_free();
113 base->remove_child(this);
114 }
115
116 base->add_child(instance);
117 base->move_child(instance, pos);
118
119 return instance;
120}
121
122void InstancePlaceholder::set_value_on_instance(InstancePlaceholder *p_placeholder, Node *p_instance, const PropSet &p_set) {
123 bool is_valid;

Callers

nothing calls this directly

Calls 9

move_childMethod · 0.80
get_nameFunction · 0.50
is_validMethod · 0.45
is_nullMethod · 0.45
instantiateMethod · 0.45
set_nameMethod · 0.45
remove_childMethod · 0.45
add_childMethod · 0.45

Tested by

no test coverage detected