godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.05k stars 65 forks source link

Automatically wait for ready before running `set` on exported properties on tool scripts in the editor #9639

Open IntangibleMatter opened 2 weeks ago

IntangibleMatter commented 2 weeks ago

Describe the project you are working on

A game with a large amount of tool scripts that set properties on their children

Describe the problem or limitation you are having in your project

When using @exports that set properties on child nodes (ex. Texture of a sprite, shape of a collisionshape, etc) you need to implement a lot of safeguards so that you don't get flooded with errors every time you load a scene.

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

When loading a node that implements a tool script, it should wait for its children to be ready before it attempts to execute any of its set functions, as setters will frequently modify other nodes when used in tool scripts. This will avoid errors when scenes are opened.

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

As opposed to the current way of doing so (below)

@export var flipped := false : 
    set(n_flipped):
        flipped = n_flipped
        if Engine.is_editor_hint():
            if not sprite.is_node_ready():
                await sprite.ready
            sprite.flip_h = flipped

It could be written like so

@export var flipped := false : 
    set(n_flipped):
        flipped = n_flipped
        if Engine.is_editor_hint():
            # safe assuming sprite exists, rather than only if the scene is already fully loaded
            sprite.flip_h = flipped

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

There may be other ways of writing this, but this is about reducing 10 lines of script to about 5

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

Part of core editor loading system

Bugsquad edit: Fix formatting.

dalexeev commented 2 weeks ago

Related: