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

PackedScene.instance() is slow with no way to make it interactive #43439

Closed
winston-yallow opened this issue Nov 10, 2020 · 1 comment
Closed
Labels

Comments

@winston-yallow
Copy link
Contributor

Godot version:
v3.2.3.stable.official

OS/device including version:
OS: Solus x86_64 (Kernel 5.6.19-159.current)
CPU: Intel i5-7400
GPU: NVIDIA GeForce GTX 1050
Backend: GLES3

Issue description:
I am creating a chunk loader. Calling scene.instance() is slow and causes a noticeable lagging even for simple scenes.
I think the best solution would be the possibility to split instancing over multiple frames. PackedScene could have a
method instance_interactive() that works in a similar way as ResourceLoader.load_interactive().
I also tried instancing the scene in a thread but ran into issue #36793.

Steps to reproduce:

Instance a scene that contains a few primitives and materials, for example with this code:

var scene := preload('res://Test.tscn')

func _input(event: InputEvent) -> void:
    if event.is_action_pressed('ui_cancel'):
        var start_instancing := OS.get_system_time_msecs()
        var node := scene.instance()
        prints('Time for instancing:', OS.get_system_time_msecs() - start_instancing)
        
        var start_adding := OS.get_system_time_msecs()
        add_child(node)
        prints('Time for adding child node:', OS.get_system_time_msecs() - start_adding)

Pressing ui_cancel causes a small lag the first time the scene is instanced, but not for subsequent calls.

Minimal reproduction project:
Run the attached project and move around with WASD. Press Escape (or any other ui_cancel action) to instance a scene while moving to notice the lag.
Check the debug output to see the time it took to instance the scene. On my computer it takes 40ms to instance the scene located at ./wip/chunks/Complex.tscn.

Project: bug.zip

@Calinou
Copy link
Member

Calinou commented Nov 10, 2020

This should be discussed in a feature proposal, not a bug report 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants