Skip to content

Commit b07eeff

Browse files
committed
Fix MaterialOps issues
1 parent 19f6252 commit b07eeff

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

MCPForUnity/Editor/Helpers/MaterialOps.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public static bool ApplyProperties(Material mat, JObject properties, JsonSeriali
110110
string texPath = (texProps["path"] ?? texProps["Path"])?.ToString();
111111
if (!string.IsNullOrEmpty(texPath))
112112
{
113-
var newTex = AssetDatabase.LoadAssetAtPath<Texture>(texPath); // Assuming path is sanitized or valid
113+
var sanitizedPath = AssetPathUtility.SanitizeAssetPath(texPath);
114+
var newTex = AssetDatabase.LoadAssetAtPath<Texture>(sanitizedPath);
114115
// Use ResolvePropertyName to handle aliases even for structured texture names
115116
string candidateName = string.IsNullOrEmpty(rawName) ? "_BaseMap" : rawName;
116117
string targetProp = ResolvePropertyName(mat, candidateName);
@@ -254,7 +255,8 @@ public static bool TrySetShaderProperty(Material material, string propertyName,
254255
// We need to handle texture assignment here.
255256
// Since we don't have easy access to AssetDatabase here directly without using UnityEditor namespace (which is imported),
256257
// we can try to load it.
257-
Texture tex = AssetDatabase.LoadAssetAtPath<Texture>(path); // Or AssetPathUtility.Sanitize?
258+
var sanitizedPath = AssetPathUtility.SanitizeAssetPath(path);
259+
Texture tex = AssetDatabase.LoadAssetAtPath<Texture>(sanitizedPath);
258260
if (tex != null)
259261
{
260262
material.SetTexture(propertyName, tex);

0 commit comments

Comments
 (0)