DreamShaderLang
编译器行为

诊断与排错

DreamShaderLang 常见错误、定位来源和处理方法。

DreamShaderLang 的错误大致分为四层:本地编辑诊断、解析错误、生成错误、Unreal 材质编译错误。

诊断来源

来源说明
VSCode 本地诊断编辑时发现语法、引用和简单语义问题。
Unreal Parser保存或重编时解析 .dsm / .dsh
Material Generator创建节点、连接输出、应用设置时产生。
Unreal Material CompilerUnreal 自身材质编译报错。

Source map

.dsm import 了 .dsh,DreamShader 会尽量把错误映射回真实源文件行列:

DShader/Shared/Common.dsh:12:5

这对共享 helper 很重要。否则所有错误都会落到展开后的合并文本里,难以定位。

常见解析错误

错误原因处理
Shader(Name="...") is requiredShader 缺少 Name补上资产路径。
Only one top-level Shader block is currently supported一个文件里写了多个 Shader拆成多个 .dsm
Shader must provide a Graph blockShader 没有 Graph添加 Graph = { ... }
Unknown shader sectionShader 中写了不支持的 section。使用 Properties / Settings / Outputs / Graph
Shader graph sections now use Graph还在 Shader 里使用 Code改为 Graph
Namespace may only contain Function blocksnamespace 里放了其他顶层块。只保留 Function

常见 Graph 错误

错误原因处理
Unknown Graph function函数未定义或未 import。检查 import 和 namespace。
Graph variable is declared more than once重复声明局部变量。改名或复用已有变量。
Arithmetic operators cannot be applied to Texture2D values对纹理对象做算术。先采样,或只对采样结果运算。
String literals can only be used in named UE builtin arguments字符串作为普通值使用。只在 UE.* 命名参数里使用字符串。
Graph if condition ... must evaluate to a scalar value条件不是标量。使用 .r.x 或 ComponentMask。
Graph if statement cannot select Texture2D value分支选择纹理对象。分支选择采样后的数值。

Function 调用错误

错误原因正确写法
must be called with explicit out variablesFunction 当返回值函数。ApplyTint(a, b, result);
currently uses positional arguments only使用了命名参数。Fn(a, b, outValue);
out argument must be a plain variable nameout 位置传了表达式。先声明变量再传入。
expects N arguments输入和输出目标数量不对。参数数量必须等于 inout

UE builtin 错误

错误原因处理
Unsupported UE builtin call调用了未注册的 UE.*,又没写 OutputType使用 UE.Expression(..., OutputType="...")
Generic UE.* calls require named arguments泛型调用用了位置参数。改成命名参数。
Class must be a literal valueClass 不是字符串或字面量。Class="Sine"
OutputType is not supported输出类型不在支持范围。使用 float1/2/3/4 或纹理类型。
OutputIndex is out of range输出索引不存在。检查 MaterialExpression 输出。

材质输出错误

错误原因处理
Unsupported material outputBase.* 名称不支持。输出绑定
bound material property expects a different type输出变量类型与目标不匹配。修改声明类型或绑定目标。
Expression output target must use .Pin[index]辅助输出节点格式错误。使用 Expression(Class="...").Pin[0]

排错顺序

  1. 先看 VSCode 红线,修掉明显语法和 import 问题。
  2. 执行 DreamShaderLang: Recompile Current Source
  3. 看 Unreal Output Log 或 VSCode 桥接诊断。
  4. 如果是材质编译器错误,定位到生成的 Custom 节点代码。
  5. 对复杂逻辑,先缩小到最小 .dsm,再逐步恢复 import 和 helper。

On this page