godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.17k stars 98 forks source link

Expanding VisualScriptEngineSingleton to use autoload singletons #2764

Closed Gallilus closed 3 years ago

Gallilus commented 3 years ago

Describe the project you are working on

General improvements to VisualScript and learning the workflow

Describe the problem or limitation you are having in your project

There is no easy way in VisualScript to use autoload singletons. Maybe not even a correct way

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

[4.0] I would like to rename VisualScriptEngineSingleton to VisualScriptSingleton
[3.x] I would like to expand VisualScriptEngineSingleton

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

VisualScriptEngineSingleton would keep working as is. Only access the autoload singletons.

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

This is the known workaround. As you see it is not user friendly image

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

It's a core node of VisualScript that implements Basic language instructions. It should run reliably and be flexible.

My exploratory work.

successes

When inserting the following snippet between lines The editor is able the have the class selectable

` List singletons;

List<PropertyInfo> props;
ProjectSettings::get_singleton()->get_property_list(&props);

for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) {
    String s = E->get().name;
    if (s.begins_with("autoload/")) {
        Engine::Singleton pi;
        pi.name = s.lstrip("autoload/");
    //  pi.ptr = Engine::get_singleton()->get_singleton_object(s.lstrip("autoload/"));
        singletons.push_back(pi);
    }
}

Engine::get_singleton()->get_singletons(&singletons);`

Not jet found a solution

I need to be able to reference the singleton object for 2 reasons. 1 So the editor will provide proper typehints 2 So the runtime is able to provide obj.reference to connected nodes I think this is done by giving the Engine::Singleton pi; pi.ptr =??

Gallilus commented 3 years ago

Fixed it using https://godotengine.org/asset-library/asset/1015