DirAccess::remove_absolute(const String &p_path) Not working.
Godot version
4.5.dev (ca452113d430cb96de409a297ff5b52389f1c9d9)
godot-cpp version
4.5.dev (e53489bbbe9a655197a41b2ed94b7f5e29ed80d2)
System information
Windows 11, Intel i9 14900K
Issue description
Using DirAccess::remove_absolute(const String &p_path) doesn't delete a .tres ShaderMaterial file.
Steps to reproduce
I've created a plugin repo: https://github.com/Fristender/MatLinkScript. The relevant code is in Matlink.cpp:
//...
void MatLink::create_material(const String &shader_path, const String &new_material_path) {
UtilityFunctions::print("MatLink::create_material - Starting with shader: ", shader_path);
UtilityFunctions::print("MatLink::create_material - Output path: ", new_material_path);
// Delete existing material file if it exists to ensure clean overwrite
if (FileAccess::file_exists(new_material_path)) {
UtilityFunctions::print("MatLink::create_material - Existing material file found, deleting: ", new_material_path);
Error delete_error = DirAccess::remove_absolute(new_material_path);
if (delete_error != OK) {
UtilityFunctions::print("MatLink::create_material - Warning: Failed to delete existing material file: ", new_material_path, " Error code: ", delete_error);
} else {
UtilityFunctions::print("MatLink::create_material - Successfully deleted existing material file");
}
}
//...
This code for creating a material first deletes any existing materials with the same file name and file path.
You can edit and run a script by double-clicking the .mlnk files in res://MatLinkScripts/, which will open an editor in the top left panel.
Here are my findings with the minimal reproduction project below:
Scenario 1:
- You run res://MatLinkScripts/Create_Material.mlnk first
- The shader for the material
res://Materials/WeirdShape_Material.tresis set tores://Shaders/text_shader.gdshader, as expected - You want to change the shader to
res://Shaders/visual_shader.tresand assignres://Textures/wood_door_01_BaseColor.pngto the BaseColor, so you runres://MatLinkScripts/Reassign_Shader.mlnk. - You re-open
res://Materials/WeirdShape_Material.tresin the inspector. - You discover that the shader is still
res://Shaders/text_shader.gdshaderand that there isn't a BaseColor parameter. The fact that the shader isn't changed tores://Shaders/visual_shader.tresis unexpected. - You look at
res://Meshes/WeirdShape.fbxand confirm that the shader and shader parameters indeed haven't changed.
Scenario 2: (Re-import res://Meshes/WeirdShape.fbx and uncheck "External Override" for "Material" and delete res://Materials/WeirdShape_Material.tres if you just ran Scenario 1.)
- You run
res://MatLinkScripts/Reassign_Shader.mlnkfirst. - The shader for
res://Materials/WeirdShape_Material.tresbecomesres://Shaders/visual_shader.tresand the BaseColor shader parameter isres://Textures/wood_door_01_BaseColor.png, as expected. - You look at
res://Meshes/WeirdShape.fbxand confirm that the shader and shader parameter is working as expected.
I think that the shader not being changed in Scenario 1 is due to erroneous file deletion.
Minimal reproduction project
Github upload always fails. https://gofile.io/d/rVWiFl