You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot4中Material.tres使用旧弃用参数名的警告问题

解决Godot 4中Canvas Item Shader的旧弃用参数名警告

问题描述

在Godot 4正式稳定版中,将以下Canvas Item类型的Shader附加到Color Rect后,运行场景时反复收到警告:

W 0:00:01:0839 _set: This material (containing shader with path: 'res://addons/scene_manager/scene_manager.tres::Shader_vksmm') uses an old deprecated parameter names. Consider re-saving this resource (or scene which contains it) in order for it to continue working in future versions.
<C++ Source> scene/resources/material.cpp:184 @ _set()

使用的Shader代码:

shader_type canvas_item;

uniform sampler2D custom_texture;
uniform float cutoff: hint_range(0, 1) = 1;
uniform float smoothness: hint_range(0, 1) = 0.1;
uniform vec3 color = vec3(0, 0, 0);
uniform bool inverted = false;
uniform bool linear_fade = true;

void fragment() {
    if (!linear_fade) {
        float value = texture(custom_texture, UV).r;
        if (inverted) {
            value = 1.0 - value;
        }
        float alpha = smoothstep(cutoff, cutoff + smoothness, value * (1.0 - smoothness) + smoothness);
        COLOR = vec4(color.rgb, alpha);
    } else {
        COLOR = vec4(color.rgb, (1.0 - cutoff));
    }
}

解决步骤

  1. 重新保存Shader资源
    找到对应的Shader文件(若Shader内嵌在材质中,打开材质的Shader编辑面板),无需修改代码,直接点击编辑器顶部的保存按钮(快捷键Ctrl+S)。

  2. 重新保存关联的材质资源
    打开警告中指定的材质文件res://addons/scene_manager/scene_manager.tres,确认Shader引用无误后,保存该材质。

  3. 重新保存场景文件
    打开包含该Color Rect的场景文件,直接保存场景,确保资源关联更新。

  4. 清理Shader缓存(若上述步骤无效)

    • 关闭Godot编辑器
    • 删除项目根目录下.godot文件夹中的shader_cache子目录
    • 重新打开项目,重复步骤1-3

原因说明

该警告通常是因为材质/Shader资源中保留了Godot 3时代的旧参数命名映射缓存,即使Shader代码本身已经符合Godot 4的规范,资源文件的元数据仍未更新。重新保存资源会让Godot重新生成适配新版本的参数定义,清理缓存则能彻底移除旧的无效数据。

内容的提问来源于stack exchange,提问作者Mahmood

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 17:52:49