godotengine / godotengine/godot-cpp

DirAccess::remove_absolute(const String &p_path) Not working.

Open
#1,831 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.7k
Forks
809
Avg merge
1d 3h
Merged PRs (30d)
8

Description

### 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:
1. You run res://MatLinkScripts/Create_Material.mlnk first
2. The shader for the material `res://Materials/WeirdShape_Material.tres` is set to `res://Shaders/text_shader.gdshader`, as expected
3. You want to change the shader to `res://Shaders/visual_shader.tres` and assign `res://Textures/wood_door_01_BaseColor.png` to the BaseColor, so you run `res://MatLinkScripts/Reassign_Shader.mlnk`.
4. You re-open `res://Materials/WeirdShape_Material.tres` in the inspector.
5. You discover that the shader is still `res://Shaders/text_shader.gdshader` and that there isn't a BaseColor parameter. The fact that the shader isn't changed to `res://Shaders/visual_shader.tres` is unexpected.
6. You look at `res://Meshes/WeirdShape.fbx` and 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.)
1. You run `res://MatLinkScripts/Reassign_Shader.mlnk` first.
2. The shader for `res://Materials/WeirdShape_Material.tres` becomes `res://Shaders/visual_shader.tres` and the BaseColor shader parameter is `res://Textures/wood_door_01_BaseColor.png`, as expected.
3. You look at `res://Meshes/WeirdShape.fbx` and 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.