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

Very noticeable stutter / lag when adding children to scene tree. #75369

Open
caliber06 opened this issue Mar 26, 2023 · 7 comments
Open

Very noticeable stutter / lag when adding children to scene tree. #75369

caliber06 opened this issue Mar 26, 2023 · 7 comments

Comments

@caliber06
Copy link

Godot version

4.0

System information

Windows 10, Forward+, i5-10400

Issue description

adding children to the scene tree results in a noticeable stutter in increase in frametime.
Godot_v4 0-stable_win64_2qFhmtxkW7
(all those spikes are when adding children)

Steps to reproduce

just add a child of a loaded instance using add_child()

Minimal reproduction project

N/A

@Calinou
Copy link
Member

Calinou commented Mar 26, 2023

@caliber06 Please upload a minimal reproduction project to make this easier to troubleshoot.

Can you reproduce this when doing the same operation in 3.5.2?

@TokisanGames
Copy link
Contributor

What is the child?

Is it a scene that has not been displayed on screen before this moment? (shader compilation)

Is it the same exact object being re-instanced on all of those spikes?

Does the object have any scripts attached?

Does the lag occur if you unattach and reattach the object from the scene tree? You should test on the same and subsequent frames. Use call_deferred for the latter.

just add a child of a loaded instance using add_child()

So it is not occuring when the object is instanced with .new() or load(). You already have an instance ready to go, eg created in _ready() and only when you add_child() it stutters? Or are you instancing the object and adding it to the tree all in one function? If so, test them independently.

Very noticeable stutter / lag when adding children to scene tree

What is stuttering? Is it just the blue ticks on the chart? These are insignificant, all about 1/60th of a second. Or does the whole engine seize? Does the mouse cursor move during the lag?

@caliber06
Copy link
Author

What is the child?

Is it a scene that has not been displayed on screen before this moment? (shader compilation)

Is it the same exact object being re-instanced on all of those spikes?

Does the object have any scripts attached?

Does the lag occur if you unattach and reattach the object from the scene tree? You should test on the same and subsequent frames. Use call_deferred for the latter.

just add a child of a loaded instance using add_child()

So it is not occuring when the object is instanced with .new() or load(). You already have an instance ready to go, eg created in _ready() and only when you add_child() it stutters? Or are you instancing the object and adding it to the tree all in one function? If so, test them independently.

Very noticeable stutter / lag when adding children to scene tree

What is stuttering? Is it just the blue ticks on the chart? These are insignificant, all about 1/60th of a second. Or does the whole engine seize? Does the mouse cursor move during the lag?

the objects are being instanced and added at the same time. the packedscene that is being instanced has a script attached, which is a child class of a parent. I have tested instancing the object in _ready() and instancing it later on, same issue. The large AND small spikes on the graph are when adding children. The entire game freezes when adding objects to the scene tree like this. I won't be able to add a minimum-reproduction project until tomorrow.

@TokisanGames
Copy link
Contributor

Does the instanced object have a shader material on it? Does placing a permanent instance of the object in the scene fix the problem when the new ones are instantiated?

@takhimi
Copy link

takhimi commented Apr 3, 2023

I notices the same problem also. Godot 3.5.2(in GDScript and C#) is more stable and faster on adding and queuefree() the children nodes.

I just tested by adding 1000-2000 AnimatedSprite2D with one animation to test it. Nothing fancy.

@Calinou
Copy link
Member

Calinou commented Apr 3, 2023

If you can compile from source or use a precompiled debug build, try using a C++ profiler on a debug build to see what's taking the most time.

Edit: Please also test #75627 🙂

@takhimi
Copy link

takhimi commented Apr 3, 2023

If you can compile from source or use a precompiled debug build, try using a C++ profiler on a debug build to see what's taking the most time.

Edit: Please also test #75627 🙂

I should learn all this checkout , patch, branch etc2 from github first.

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

4 participants