dreadpon / godot_spatial_gardener

A Godot plugin for painting plants and props on arbitrary 3D surfaces implemented in GDScript
MIT License
849 stars 37 forks source link

[BUG] (?) Hitching in editor #42

Open SlashScreen opened 7 months ago

SlashScreen commented 7 months ago

On the latest stable release, I have a lot of trees, and the editor hitches as I move the camera around (but in-game it seems fine). Is this something other people have seen? Should I try a nightly version?

SlashScreen commented 7 months ago

Hang on, my garden is using TRES instead of RES. That might be an issue. Is there an easy way to change which it's using?

dreadpon commented 7 months ago

Hang on, my garden is using TRES instead of RES. That might be an issue. Is there an easy way to change which it's using?

Where exactly is it using tres instead of res? I don't think any critical code really depends on res over tres though

dreadpon commented 7 months ago

On the latest stable release, I have a lot of trees, and the editor hitches as I move the camera around (but in-game it seems fine). Is this something other people have seen? Should I try a nightly version?

You need to provide a bit more info than that. How big is your scene? How many plants are you creating? Are you using scenes or mesh resources in your drawing process? Is there anything of note in the console when hitches occur? Do you have a Minimal Reproduction Project that I can test?

SlashScreen commented 7 months ago

Where exactly is it using tres instead of res? I don't think any critical code really depends on res over tres though

The garden work directory - greenhouse.tres, toolshed.tres. From experience I have learned that for larger/more often accessed files, .res can improve times related to parsing/serializing significantly.

You need to provide a bit more info than that. How big is your scene?

Sorry, I wrote this late at night. The scene is rather large, with over a thousand trees with collision nodes spawned. I'm using mesh resources, as far as I know, apart from the collision thing. The console says nothing. I don't have a minimal reproduction project at the moment.

dreadpon commented 7 months ago

The setup you describe shouldn't cause much hitching.

Currently, the only thing that I know of that may cause these problems is spawning/respawning nodes when an LOD changes. But it usually has to spawn/despawn hundreds of nodes at a time...

Can you please enable the debug draw for your trees (at the top of 3D viewport when a Gardener is selected) and demonstrate the hitching on a video recording? Might be something about your setup that causes this, theoretically.

And/or give me an MRP, whenever you have the time.

SlashScreen commented 7 months ago

Here's a MRP. Just scrolling in and out should show it. Perhaps the problem is that the octree sizes are too big, and so it's not spawning a lot of things.

test.zip

SlashScreen commented 7 months ago

Changing the number of trees per chunk to be smaller did not change hitching.

dreadpon commented 7 months ago

Can confirm the hitching, but there doesn't seem to be any bug causing this. So far, seems to just be how Godot behaves when adding tens/hundreds of nodes at once in the editor. In-game indeed works fine.

Tried adding nodes with INTERNAL flag, tried not giving an owner, tried naming them manually, doesn't seem to make a difference.

Will investigate further, but it's possible that a proper fix (offloading to threads or something similar) will be delayed for a major version (v2.x.x for example) because this potentially might be a breaking change.

SlashScreen commented 7 months ago

Before you try this: I've done testing when I was working with ProtonScatter, and instantiating a packed scene is much faster than duplicating a tree.

The fact that it's editor-only implies to me that the problem is adding nodes repeatedly to the editor scene tree; so what if you created an orphan node, added the static bodies to that node, and then added the orphan node to the scene, performing the operation all at once?

Should I pursue this avenue?

ar-russ commented 6 months ago

Hi! Any known workaround for this issue? I have around ~2500 objects placed by gardener overall and it causes significant lags in editor, which makes usage of plugin rather painful

ar-russ commented 6 months ago

@dreadpon maybe you could add checkbox for turning off processing octrees and/or LODs for objects in editor?

SlashScreen commented 6 months ago

I tried the static bodies node idea I had, but it didn't result in any performance gains. Is it critical that the tree be visible within the editor tree?

dreadpon commented 6 months ago

@dreadpon maybe you could add checkbox for turning off processing octrees and/or LODs for objects in editor?

Upon profiling the engine, the problem does not appear to be fixable on my side. It's just a byproduct of updating AABBs, node names, owners and so on.

So an option to selectively stop processing certain features will most likely be the way I'll handle this, yes.