Unable to modify custom shader's properties in scripts' update?
See original GitHub issueI’ve managed to set up my shader’s SoftMaskable version. But now I can’t change the shader’s properties at runtime.
Shader "Hidden/Custom/UI/Grayscale (SoftMaskable)"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_StencilComp ("Stencil Comparison", Float) = 8
_Stencil ("Stencil ID", Float) = 0
_StencilOp ("Stencil Operation", Float) = 0
_StencilWriteMask ("Stencil Write Mask", Float) = 255
_StencilReadMask ("Stencil Read Mask", Float) = 255
_EffectAmount ("Effect Amount", Range (0, 1)) = 1.0
_BrightnessAmount ("Brightness Amount", Range(0.0, 3)) = 1.0
_ColorMask ("Color Mask", Float) = 15
}
...
And this is how I set properties in Update (for a short period of time):
LevelImage.material.SetFloat("_EffectAmount", amount);
If I click on the Material in the object’s Renderer itself, it shows the correct effect amount, but under the object, it displays the Hidden Soft Maskable material, with unchangeable default properties.
How could I fix this?
Thanks in advance! 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Unity cannot edit shader property in script
I have a material with a custom shader on it. The shader has a property called _sliceValue that I want to edit inside...
Read more >How to change a value in custom shader through script, C# ...
Hi! I´m using a shader that i found on the net, called “Blend 2 Textures” Here´s the shader: Shader "Blend 2 Textures" {...
Read more >Error when changing Scripts - Unity Forum
This error seems to pop up every time I change code in Entities.ForEach. Restarting the editor fixes the problem, but it's very annoying ......
Read more >Unity Shader Graph - Changing Parameters in Script - YouTube
... our Discord: https://discord.gg/sn9xXK4 In this video I show you how to show you how to change a shader's parameters in a C#...
Read more >Shader Graph and C# Interaction! Set Properties from Scripts ...
Works in 2020.1 ➕ 2020.2 ➕ 2020.3 Oftentimes, it's useful to set shader properties from a C# script. In this video, I show...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mob-sakai Thanks, yes, it’s only null at the first frame. 😃 (In the last (now deleted) comment I said that it’s constantly null, but it was null only due to an issue on my side)
@mob-sakai For some reason CanvasRenderer.GetMaterial() returns null :\