Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting animation save paths on import breaking on Windows #90003

Merged
merged 1 commit into from
Apr 4, 2024

Conversation

AlexOtsuka
Copy link
Contributor

Fixes #86279.

Blender uses the | (pipe or vertical bar) character in its animation names which is forbidden in Windows file names. My fix simply replaces those with a _ (underscore) in the automatic path suggestion code when using the "Set Animation Save Paths" option.

There are other possible approaches to this, such as:

  • Immediately renaming all the strings containing a | character on import => probably breaks compatibility with older projects
  • Renaming ALL strings containing a | character when saving => probably breaks compatibility with older projects
  • Making this change Windows only => would create discrepancies between different operating systems
  • Using a different character => I'm open to suggestions

I chose to go for this as it seems like a safe, convenient fix with no obvious downsides.

@AlexOtsuka AlexOtsuka requested a review from a team as a code owner March 29, 2024 03:15
@AThousandShips AThousandShips added this to the 4.3 milestone Mar 29, 2024
@AThousandShips AThousandShips added the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Mar 29, 2024
Copy link
Contributor

@lyuma lyuma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes an important bug on windows, so I'm approving this because 99% of the problem cases are covered by the change as written and I want to make sure it gets in.

Just a comment but should we check if material and mesh extraction has the same problem? perhaps we should validate_filename() in all cases

I think this problem stemmed because the Extract window doesn't offer a way to rename the extracted animations. I don't think people ever want their animations to be named "Armature|" or "Armature_" or "Take 001", but it's hard to edit from the extract dialog.

Anyway, improving the extraction flow would require an updated design, and it's important to get this bug fixed, so I think this is a good change.

@@ -1448,7 +1448,8 @@ void SceneImportSettingsDialog::_save_dir_callback(const String &p_path) {
item->set_metadata(0, E.key);
item->set_editable(0, true);
item->set_checked(0, true);
String path = p_path.path_join(name);
// Replacing | (pipe) with _ (underscore) for compatibility with the Windows file system.
String path = p_path.path_join(name.replace("|", "_"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider using String::validate_filename() instead of specifically replacing | with _. Basically, there are many illegal filename characters and we should replace all of them.

the validate_filename will replace characters with _ so it should work the same for the case you did.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your replies.

As far as I know, this only automatically happens in animation names in Blender, but I guess anyone could actually insert | in whatever they decide to name their material and meshes names.

I agree String::validate_filename() is better, I didn't know it existed and it's perfect for the use case. I guess I'll change that and wrap both the material and mesh names in the method as well.

A cool addition to this imo would be to display an error message or a pop-up whenever a user is trying to save their resources using invalid characters, as the previous error was a little cryptic. I don't know how much value there is in letting non-windows users use those characters in filenames either. What do you think would be the most appropriate solution?

For now, I'm gonna make the quick changes you mentioned and force-push them asap!

@AlexOtsuka AlexOtsuka force-pushed the fix-animation-save-paths branch from f5eb9b0 to 4d3319e Compare March 30, 2024 23:52
@akien-mga akien-mga added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Apr 4, 2024
@akien-mga akien-mga merged commit 77a9cf0 into godotengine:master Apr 4, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@AlexOtsuka AlexOtsuka deleted the fix-animation-save-paths branch April 4, 2024 18:29
@akien-mga
Copy link
Member

Cherry-picked for 4.2.2.

@akien-mga akien-mga removed the cherrypick:4.2 Considered for cherry-picking into a future 4.2.x release label Apr 8, 2024
@akien-mga
Copy link
Member

Cherry-picked for 4.1.4.

@akien-mga akien-mga removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Apr 8, 2024
@akien-mga akien-mga changed the title Fix Set Animation Save Paths breaking on Windows Fix setting animation save paths on import breaking on Windows Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set Animation Save Paths fails on animations containing "|" characters
4 participants