Add change_scene_to_node()
This commit is contained in:
@@ -1690,6 +1690,13 @@ Error SceneTree::change_scene_to_packed(const Ref<PackedScene> &p_scene) {
|
||||
Node *new_scene = p_scene->instantiate();
|
||||
ERR_FAIL_NULL_V(new_scene, ERR_CANT_CREATE);
|
||||
|
||||
return change_scene_to_node(new_scene);
|
||||
}
|
||||
|
||||
Error SceneTree::change_scene_to_node(Node *p_node) {
|
||||
ERR_FAIL_NULL_V_MSG(p_node, ERR_INVALID_PARAMETER, "Can't change to a null node. Use unload_current_scene() if you wish to unload it.");
|
||||
ERR_FAIL_COND_V_MSG(p_node->is_inside_tree(), ERR_UNCONFIGURED, "The new scene node can't already be inside scene tree.");
|
||||
|
||||
// If called again while a change is pending.
|
||||
if (pending_new_scene_id.is_valid()) {
|
||||
Node *pending_new_scene = ObjectDB::get_instance<Node>(pending_new_scene_id);
|
||||
@@ -1707,7 +1714,7 @@ Error SceneTree::change_scene_to_packed(const Ref<PackedScene> &p_scene) {
|
||||
}
|
||||
DEV_ASSERT(!current_scene);
|
||||
|
||||
pending_new_scene_id = new_scene->get_instance_id();
|
||||
pending_new_scene_id = p_node->get_instance_id();
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1922,6 +1929,7 @@ void SceneTree::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("change_scene_to_file", "path"), &SceneTree::change_scene_to_file);
|
||||
ClassDB::bind_method(D_METHOD("change_scene_to_packed", "packed_scene"), &SceneTree::change_scene_to_packed);
|
||||
ClassDB::bind_method(D_METHOD("change_scene_to_node", "node"), &SceneTree::change_scene_to_node);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("reload_current_scene"), &SceneTree::reload_current_scene);
|
||||
ClassDB::bind_method(D_METHOD("unload_current_scene"), &SceneTree::unload_current_scene);
|
||||
|
||||
@@ -424,6 +424,7 @@ public:
|
||||
Node *get_current_scene() const;
|
||||
Error change_scene_to_file(const String &p_path);
|
||||
Error change_scene_to_packed(const Ref<PackedScene> &p_scene);
|
||||
Error change_scene_to_node(Node *p_node);
|
||||
Error reload_current_scene();
|
||||
void unload_current_scene();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user