godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Add better scene state tracking with signals for node property changes #10539

Open zodywoolsey opened 2 months ago

zodywoolsey commented 2 months ago

Describe the project you are working on

A social VR platform that exposes tooling to create things at runtime and networks everything it can in the engine with some security on top.

Describe the problem or limitation you are having in your project

Currently the only way to track all scene state changes is to use the observer pattern and manually keep duplicate state data to detect when properties on nodes change. It's too performance heavy to track scene changes this way and does not scale well. Especially on low end devices like my minimal performance target, the Quest 1

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

Object and it's inheritors should include a changed signal just like resources. This changed signal should also have some option to propagate that notification up the tree so a portion of the tree can be tracked without only having the option of signal hooks to every node.

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

When any property is changed on an Object, it should emit a signal and optionally a signal that gets sent to the parent node until that signal hits the tree root. The signal on the Object itself could be called changed like it is in Resources or object_configuration_changed and the one that moves up the tree could be called tree_configuration_changed or something similar that is more indicative of what's going on there.

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

It depends on the complexity of what needs to be synced from the scene. In my case, it's everything so the overhead is immense. This could also, potentially, dramatically optimize Godot's high level multiplayer functionality since it currently iterates over all the configured nodes every tick and could watch the tree for changes and respond only when something changes.

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

It isn't possible to implement this functionality in a way that can scale right now.

Calinou commented 2 months ago

Object and it's inheritors should include a changed signal just like resources

This would make the Object class larger in scope and functionality, which will increase the base memory consumption of all Godot projects even if they don't use this feature. In general, base classes (Object/RefCounted/Node) should try to remain as minimal as possible for this reason, only adding features as absolutely needed.

zodywoolsey commented 2 months ago

i believe the performance benefit for multiplayer situations would be pretty significant just with adding this single signal on the Object class. it would make it so a duplicate scene representation is actually avoidable in multiplayer situations with complex scene state syncing. I can implement it locally and test impact with various situations and report back later.

AThousandShips commented 2 months ago

Related: