limbonaut / limboai

LimboAI - Behavior Trees and State Machines for Godot 4
https://limboai.readthedocs.io/
MIT License
1.22k stars 47 forks source link

Inconsistent edit and save behavior for embedded `BehaviorTree`s #240

Open ydeltastar opened 1 week ago

ydeltastar commented 1 week ago

Godot version

4.3

LimboAI version

1.3-dev

LimboAI variant

GDExtension / AssetLib

Issue description

Embedded resources are considered read-only when the editor is not focused on the scene that holds them. In the BT editor, the inspector becomes read-only but the tree can still be edited.

It looks like it works with the default editor settings because it forces all scenes to save but when run/auto_save/save_before_running is disabled, manual save doesn't work for embedded BT of other scenes so changes are never applied.

How to reproduce

limbonaut commented 1 week ago

Ctrl+S is bound to "Save Scene" - so it wouldn't work in such case. It's Ctrl+Alt+S to save the current BT, but it's broken anyway - even on button click. I made a PR to fix it.

ydeltastar commented 1 week ago

Other resource editors, such as the script and shader editor, save embedded with Ctrl+S when their scenes are not focused. After taking a look at the source, I think this can be solved with EditorPlugin._save_external_data because it is called on all plugins when any scene saves.

limbonaut commented 1 week ago

EditorPlugin._save_external_data is called by the EditorNode when a scene is saved. Asking a scene to be saved in that callback creates a circular call dependency loop. I think, we'd need a reliable dirty state tracking to break such a loop, but currently the dirty state tracking is not very reliable. Every task would need to report changes with _emit_changed() for it to work, and I feel like it's too much to ask from users. Every core task is calling emit_changed, but how many people actually implement emit_changed in their setters? So currently we assume that everything is dirty all the time (there is still code to track dirty state, but it's unused).

PS: It's kinda weird that "Save Scene" command ends up saving every change in the editor, which can also end up saving other scenes too (but not all of them necessarily?). It's probably because there is no dependency graph implemented for resources.

limbonaut commented 1 week ago

A little bit more context... Currently, script editor behaves like this:

ydeltastar commented 1 week ago

PS: It's kinda weird that "Save Scene" command ends up saving every change in the editor, which can also end up saving other scenes too (but not all of them necessarily?). It's probably because there is no dependency graph implemented for resources.

The saving process is overall a bit hacky in the engine. I don't use autosave, for example, because it tries to save every scene open in the editor so some resources also save multiple times, it triggers multiple filesystem_changed signals, some editors do heavy operations after it, and other issues. It snowballs the more files a project has and slows down project startup a lot waiting for the process to finish. Manually saving at least affects a single scene and a few files so it is much faster.

Well, the worst-case scenario is losing changes so I understand going for redundancy if it means avoiding losing data. A dependency graph could help for sure.

Every task would need to report changes with _emit_changed() for it to work, and I feel like it's too much to ask from users. Every core task is calling emit_changed, but how many people actually implement emit_changed in their setters? So currently we assume that everything is dirty all the time (there is still code to track dirty state, but it's unused).

Maybe EditorProperty or EditorInspector can solve this. It has signals for property changes so the dirty tracking logic could rely on the inspector itself.

limbonaut commented 1 week ago

Maybe EditorProperty or EditorInspector can solve this. It has signals for property changes so the dirty tracking logic could rely on the inspector itself.

It's a promising concept. Might be a good solution if we can make it handle properties with built-in resources somehow.

limbonaut commented 1 week ago

243 fixes built-in resources not being saved on save action (UI button or Ctrl-Alt-S). Keeping this open, because it's only partly addressed. I think that pressing Ctrl+S should affect what is on screen right now, and it's not always the case.