godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 68 forks source link

Add "Remember Path" setting for attaching scripts to nodes #3332

Open SirQuartz opened 2 years ago

SirQuartz commented 2 years ago

Describe the project you are working on

In Godot, when you go to attach a script to a node the engine will automatically start the path from the same directory as the scene you're in. This is fine if you're following the documentation's recommended way of organizing your projects, but if you prefer to do it your own way or any other way with a different folder structure and organization, this becomes much more tedious. This feature I'm working on would greatly reduce this problem and speed up workflows by giving users another option.

Describe the problem or limitation you are having in your project

Attaching scripts to your nodes is a very frequently repeated operation that becomes exponentially more tedious if you don't store your scripts in the same folder as your scenes. You spend most of that time surfing through the file system trying to get back to the folder that the engine should really just remember. The default and only behavior from the engine is to assume you always want to have your scripts in the same folder as your scenes. This means if you happen to want to do things differently it becomes way more tedious, unnecessarily so.

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

I've implemented a way for Godot to remember the last directory you were in when you last attached a script to a node. That way, the next time you attach a script to a node it will be smart enough to start from that directory first. I'm calling it "associative directory pathing" because the engine will now "associate" the last directory as the starting path when next attaching a script to a node. Of course, saying "it remembers the last directory you were in when you attached a script to a node so it can use it again later." doesn't really roll off the tongue that well, so "associative directory pathing" it is.

This helps to overcome the inconvenience of having your scripts in different folders than your scenes by remembering the last directory you were in when you attached a script last. The path will automatically start at the last location you attached a script to a node. This makes it so you don't need to navigate through nearly as many folders if you prefer this kind of organization/workflow.

Here's a video showcasing it (sound recommended):

https://user-images.githubusercontent.com/62965063/134281586-a1aea9e4-0a11-44ec-8236-3c0eee3982f0.mp4

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

This new feature would be a setting in "Editor Settings" that by default is disabled (this keeps the recommended behavior from the documentation as the default this way). It's a simple checkbox that the user can enable should they desire the feature for their workflow.

https://user-images.githubusercontent.com/62965063/134278316-66753369-52b9-4a14-a123-69eb615e165e.mp4

All it does is store a string called "a_path" (stands for "associated path") in memory when the setting is enabled. It's simply the path to the last directory you were in when you attached a script to a node.

I've already got it working and even programmed it into the engine.

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

I suspect there are a great number of people that could find this feature very useful for their daily workflow. Other developers have complained about this exact problem before.

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

It makes the most sense to be a core feature of the engine as it gives the user a different option and more control over a common operation. That way the engine isn't forcing only one particular behavior onto the user.

Calinou commented 2 years ago

Attaching scripts to your nodes is a very frequently repeated operation that becomes exponentially more tedious if you don't store your scripts in the same folder as your scenes.

The project organization workflow recommends keeping scripts in the same folders as scenes. Moving all your scripts to a separate folder is considered an antipattern.

This new feature would be a setting in "Editor Settings" that by default is disabled (this keeps the recommended behavior from the documentation as the default this way).

I would prefer not adding an editor setting that's disabled by default, as very few people will actually enable such a setting. I'm also not fond of adding settings that make it easier to deviate from the recommended workflow, unless there is a very good reason for doing so often.

SirQuartz commented 2 years ago

Attaching scripts to your nodes is a very frequently repeated operation that becomes exponentially more tedious if you don't store your scripts in the same folder as your scenes.

The project organization workflow recommends keeping scripts in the same folders as scenes. Moving all your scripts to a separate folder is considered an antipattern.

This new feature would be a setting in "Editor Settings" that by default is disabled (this keeps the recommended behavior from the documentation as the default this way).

I would prefer not adding an editor setting that's disabled by default, as very few people will actually enable such a setting. I'm also not fond of adding settings that make it easier to deviate from the recommended workflow, unless there is a very good reason for doing so often.

I already know that it's considered an "antipattern" that's why I suggested that the setting be disabled by default. That wouldn't even be that strange, lots of editor settings are disabled by default. Secondly, even if keeping scripts in the same folder as your scenes is the "recommended" approach, you shouldn't be forced to use it. I know there are a lot of people who don't follow the recommended approach simply because it's not how they like to organize things. That or they use a hybrid approach. Either way, the engine really shouldn't be deciding that for you.

So saying "very few people will enable such a setting" isn't very convincing. Maybe they just wouldn't know where to find it, in which case, I could make it a project setting instead? I don't really know if that's a better way. I considered putting the checkbox just on the attach node dialog itself, that way it is obvious and easy to find.