Files
XCEngine/docs/api/XCEngine/Components/MeshRendererComponent/GetMaterialPath.md

36 lines
1.1 KiB
Markdown

# MeshRendererComponent::GetMaterialPath
获取指定材质槽当前缓存的路径字符串。
```cpp
const std::string& GetMaterialPath(size_t index) const;
```
## 当前实现行为
- 如果 `index` 在范围内,返回 `m_materialPaths[index]`
- 如果越界,返回一个静态空字符串引用,而不是抛异常。
## 语义说明
- 这是纯元数据访问器,不会触发异步加载。
- 返回的是组件当前内存中的路径缓存,不等于最终序列化文本里的 `materialPaths=` 输出。
- 对于有效项目资产槽位,序列化时路径可能被省略到 `materialRefs=` 中,但运行时这里仍然可能保留 `Assets/...` 路径。
## 使用建议
适合用于:
- 编辑器 Inspector 或调试 UI
- 路径级日志输出
- 需要避免触发加载副作用的代码路径
真正需要访问 `Material` 对象时,仍应看 [GetMaterial](GetMaterial.md) 或 [GetMaterialHandle](GetMaterialHandle.md)。
## 相关文档
- [返回类型总览](MeshRendererComponent.md)
- [GetMaterial](GetMaterial.md)
- [GetMaterialAssetRefs](GetMaterialAssetRefs.md)
- [SetMaterialPath](SetMaterialPath.md)