I want to set alpha clipping in my material through script(URP),How can I set alpha clipping through script?(URP)
Asked Answered
D

2

0

I want to set alpha clipping in my material through script (URP), but

material.SetInt( "_AlphaClipping" , 1 );

doesnt work!

Damalas answered 7/2, 2024 at 11:44 Comment(0)
I
0

It is a bit strange but you set the bool to enable Alpha Clipping with a float

material.SetFloat("_AlphaClip", 1);
material.SetFloat("_Cutoff", 0.5f);
material.EnableKeyword("_ALPHATEST_ON");

I doubt this will help @Damalas anymore as it’s been 9 months. I hope it helps somebody

Also, you need to add EnableKeyword("_ALPHATEST_ON").

Involved answered 7/2, 2024 at 11:44 Comment(1)

Hey. This doesn't seem to work for me? Do I have to call the material.EnableKeyword("_ALPHATEST_ON"); before setting the float?

Scarrow
A
0

It did help, thank you for this. Also @Scarrow yes, you have to use it in order:

material.EnableKeyword("_ALPHATEST_ON");
material.SetFloat("_AlphaClip", 0);

When you want to set Alpha Clipping back to false, you need to:

material.DisableKeyword("_ALPHATEST_ON");
Alburnum answered 7/2, 2024 at 11:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.