0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Unity】エディタでは表示されるのにビルドするとピンクになるマテリアルの直し方

Posted at

普段シェーダーを記述することは少ない私が、今回の問題に直面し、解決した方法について紹介します。必ず本記事の方法で解決できる訳ではなく、一部の参考資料としてご利用ください。

対象環境

  • Unity 2022以上
  • URP
  • ShaderLabで記述

現象

ShaderLabで記述したシェーダーが、エディタ上では理想通りに表示されるが、ビルドをするとマテリアルエラー(ピンク)になる。

原因

Tags { "RenderPipeline" = "UniversalRenderPipeline" }

上記のようにタグを記述していた場合、次のように書くと直ります。

Tags { "RenderPipeline" = "UniversalPipeline" }

解説

実は、元々UniversalRenderPipelineと記述すること自体間違っており、Unity2021以前はこのように書いても読み込めてしまうというバグがあったそうです。そしてUnity2022以降でこのバグが修正され、正しい表記「UniversalPipeline」でないと読み込めないようになりました。
Unityのサンプルコードや様々な記事で間違った書き方がされていたため、それらを学習した生成AIでも間違ったコードが出力されることがあります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?