,Trying to change custom boolean properties of a shadergraph with EnableKeyword
My Shader works as intended through inspector. I'm trying to be able to control the boolean values of it through script but it doesn't seem to change anything in runtime, doesn't give back any errors either. could not find any helpful documentation on "EnableKeyword"\"DisableKeyword"
I've also tried using the "Boolean_E17E3BA3" reference in the script and any other capitalized with or w/o underscore variants.
any solutions other than creating child instance of the gameObject with different renderer and switching between them?
this is the shadergraph part I'm trying to control:
This is the material panel in the inspector:
and this is the test code where i try to enable/disable said property:
using UnityEngine;
public class testScript : MonoBehaviour
{
public Renderer rend;
private void Update()
{
if (Input.GetKeyDown(KeyCode. Space))
{
print("pressed space");
rend.material.EnableKeyword("_Highlight");
}
}
}
Answer by ricky_lee_ · Feb 12, 2021 at 07:40 PM
You have to set it as a float, In your case:
// for true
rend.material.SetFloat( "_Highlight" , 1.0f );
// for false
rend.material.SetFloat( "_Highlight", 0.0f );
Doesn't make sense but it works :)
Your answer
Follow this Question
Related Questions
Sprite2D CG shader: No errors, but not displaying anything 1 Answer
How to map letters on mesh with shader? 0 Answers
Among Us Masking (RGB) Question 0 Answers
ShaderGraph Y-Axis Billboard 0 Answers