Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to convert a scene to an instanced scene #2393

Closed
TrickMe opened this issue Mar 3, 2021 · 3 comments
Closed

Add a method to convert a scene to an instanced scene #2393

TrickMe opened this issue Mar 3, 2021 · 3 comments

Comments

@TrickMe
Copy link

TrickMe commented Mar 3, 2021

Describe the project you are working on

Realtime space x4 with procedurally generated galaxy.

Describe the problem or limitation you are having in your project

I noticed that it is faster to procedurally generate a game scene, while the scene is not in the tree.
So I generate the world out of tree and then add the main node to the tree.

get_tree().change_scene() and get_tree().change_scene_to() only accept PackedScenes, not nodes.
(or instanced PackedScenes, with nodes like sprites, etc. procedurally added to them)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

solutions:
1
make get_tree().change_scene() and get_tree().change_scene_to() accept instanced PackedScenes instead of PackedScenes

2
add get_tree().change_scene_instance() and get_tree().change_scene_to_instance() methods.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

solution 1:
get_tree().change_scene(newScene.instance()) instead of get_tree().change_scene(newScene)
get_tree().change_scene_to(newScene.instance()) instead of get_tree().change_scene_to(newScene)

If this enhancement will not be used often, can it be worked around with a few lines of script?

add onready var and func to Autoload "GLOBAL":

onready var currentScene:Node = get_node("/root/firstLoadedSceneName")

func change_scene(newScene:Node):
    currentScene.queue_free()
    currentScene = newScene
    get_tree().get_root().add_child(newScene)

use in script:

GLOBAL.change_scene(PackedScene.instance())

Is there a reason why this should be core and not an add-on in the asset library?

Although there is an easy workaround, I think it could be beneficial for users and beginners, who generate their game world procedurally.
The change in solution 1 is only to add .instance() to the script to update your project to work.

edit:
If a scene is added to the tree, it always has to be instanced first, change_scene() seems to be the only exception
So for consistency I encourage solution 1.

@Calinou
Copy link
Member

Calinou commented Mar 3, 2021

See also #2367.

@Calinou Calinou changed the title change scene to an instanced scene Add a method to convert a scene to an instanced scene Mar 3, 2021
@TrickMe
Copy link
Author

TrickMe commented Mar 3, 2021

Isn't the method to convert a scene to an instanced scene literally .instance()?
I'm worrying if the new headline could be misinterpreted.

@KoBeWi
Copy link
Member

KoBeWi commented Mar 3, 2021

Duplicate of #921 (former godotengine/godot#24795)

@KoBeWi KoBeWi closed this as completed Mar 3, 2021
@KoBeWi KoBeWi added the archived label Mar 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants