27
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ビルドするとShader.Findに失敗する

Posted at

ざっと検索して見つけられなかったので、いつも通りの備忘録。

Shader s = Shader.Find("Sprites/Diffuse");
if (s == null) throw new System.NullReferenceException();

上記のスクリプトを実行したとき、Unityエディタ上で実行するには問題ないが、PC, Mac & Linux Standaloneビルドしたゲームではヌルチェックにひっかかって例外がスローされる。
スクリプトリファレンスを見たら解決方法が書いてあった。

http://docs.unity3d.com/ScriptReference/Shader.Find.html から該当箇所を抜粋

add it under "Always Included Shaders" list in ProjectSettings/Graphics

Unityエディタのメニューにある Edit → Project Settings → Graphics を選択。
Inspector に GraphicsSettings が表示されるので、Always Included Shaders に Sprites/Diffuse を追加すればOK

設定前の GraphicsSettings
before.png

設定後の GraphicsSettings
after.png
Always Included Shaders の Size を 1 増やして、追加された Element 6 に Sprites/Diffuse を設定。

27
14
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
27
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?