URPでmainTextureScaleを変更するときはSetTextureScaleを使う【Unity】
July 15, 2020, 9:50 a.m. edited Aug. 7, 2020, 8:24 a.m.従来のBuilt-in Render PipelineではマテリアルのTilingを変更するとき、
material.mainTextureScale = new Vector2(2, 3);
のようにすることでできました1。しかし、Universal Render Pipeline (URP) でSimple Lit Shaderを使うとき、このように書くと
Material doesn't have a texture property '_BaseColor'
UnityEngine.Material:set_mainTextureScale(Vector2)
Property (_BaseColor) already exists. Use SetTexture instead.
UnityEngine.Material:set_mainTextureScale(Vector2)
とエラーが出てしまいます。
解決方法
material.SetTextureScale("_BaseMap", new Vector2(2, 3));
のように明示的に "_BaseMap"
を指定することで動作します。
他にも、offsetを変えるときも似たようにしてやる必要があるそうです(https://forum.unity.com/threads/kinda-solved-cant-change-texture-offset-via-script-in-urp.741044/#post-5537335)。
-
GetComponent<Renderer>().material
を呼び出したらDestroy
するのを忘れずに(ドキュメントにも書いてある)。 ↩
Tags
- #Python (26)
- #量子力学 (23)
- #量子情報 (21)
- #Unity (11)
- #Outer Wilds (11)
- #Mac (9)
- #数学 (8)
- #AoE2 (8)
- #Linux (6)
- #Quantum Zoo (6)
- #意識 (5)
- #シミュレーション (5)
- #NumPy (5)
- #Bash (5)
- #相対論 (4)
- #Docker (4)
- #Android (4)
- #Qiskit (4)
- #Rust (3)
- #PyO3 (3)
- #GitHub (3)
- #Django (2)
- #情報理論 (2)
- #LaTeX (2)
- #AR (2)
- #Git (2)
- #iOS (2)
- #C++ (2)
- #正規表現 (2)
- #電磁気学 (1)
- #Google Drive (1)
- #Overleaf (1)
- #Let's Encrypt (1)
- #ポケモン (1)
- #AdMob (1)
- #Autoya (1)
- #docopt (1)
- #SymPy (1)
- #AWS (1)
- #Twitter (1)
- #URP (1)
- #iMovie (1)
- #論文 (1)
- #PyTorch (1)
- #C# (1)
- #Vim (1)