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 progress status on PackedScene.instantiate() #4650

Closed
Uniformbuffer3 opened this issue Jun 10, 2022 · 2 comments
Closed

Add progress status on PackedScene.instantiate() #4650

Uniformbuffer3 opened this issue Jun 10, 2022 · 2 comments

Comments

@Uniformbuffer3
Copy link

Describe the project you are working on

I'm creating an RPG game where i expect to have scenes with a very high node count.

Thanks in advance for the dedicated time reading this proposal.

Describe the problem or limitation you are having in your project

I was trying to get proper loading of big scenes without holding the main thread rendering process.
I have made some tests about the topic using a scene with ~1000000 Node and they revealed that loading the resource (using load or ResourceLoader functions) is almost instant, while instancing the packed scene take all the required time.
I suppose using "real nodes" with actual data (like textures) could behave differently, but still, a big portion of the load time is used for instancing the scene.

So the feature i would like to ask it to have a way to get progresses as the instancing function keep going, so that it would be possible to make informative loading screens.

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

A way to implement such feature would be to introduce a new "async" version of the same PackedScene.instantiate and, taking inspiration from ResourceLoader.load_threaded methods, creating 3 new functions:

  • PackedScene.instantiate_threaded_get()->Node
  • PackedScene.instantiate_threaded_get_status(progress: Array = [])->ThreadLoadStatus
  • PackedScene.instantiate_threaded_request(use_sub_threads: bool = false)->Error

The only difference would be that they do not require a "path" like the ResourceLoader counterpart functions, but the PackedScene object address would be used to get the associated loading thread.

(obviously the functions are just a draft, just to give the idea)

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

It would work the same as ResourceLoader.load_threaded methods:

var packed_scene: PackedScene
packed_scene.instantiate_threaded_request()

var timer = Timer.new()
timer.autostart = true
self.add_child(timer)

var timeout_callback = func():
    var progress = []
    if packed_scene.instantiate_threaded_get_status(progress) == THREAD_LOAD_LOADED:
         var instantiated_node = packed_scene.instantiate_threaded_get()
         # Running some callback and pass the instantiated node to some other system
    print(progress[0])

timer.timeout.connect(timeout_callback)

It is just a draft (and inelegant) code, but it should give the idea of the result.

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

I think it would be possible to instantiate nodes in a packed scene one by one and rebuild the scene tree structure, but not using few lines of code.

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

Loading resources is part of the core features of the engine,

@Zireael07
Copy link

Are your scenes just Nodes or are they renderable? In the latter case, it's likely shader compiling eating time...

@Calinou
Copy link
Member

Calinou commented Jun 10, 2022

Duplicate of #1801.

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2022
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