question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to modify custom shader's properties in scripts' update?

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
udvaritiborcommented, Sep 14, 2020

@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)

1reaction
udvaritiborcommented, Sep 14, 2020

@mob-sakai For some reason CanvasRenderer.GetMaterial() returns null :\

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found