- Home /
When can I use Shader.EnableKeyword()?
I'm trying to use a preprocessor macro in my custom shader so it performs a different step if it's in the Unity Editor:
#if defined(IS_UNITY_EDITOR)
// something
#else
// other thing
#endif
To achieve this, I'm using the Shader.EnableKeyword
method in a MonoBehavior:
if (Application.isEditor) {
Shader.EnableKeyword("IS_UNITY_EDITOR");
}
However, my shader is being compiled before the monobehavior can check if it's in the unity editor. I've tried running it on Start()
and on Awake()
, but the shader never receives the IS_UNITY_EDITOR
definition. How can I enable that keyword before the shader is compiled?
Answer by xibanya · Dec 06, 2020 at 11:46 AM
in your shader you will want to make sure that you have a line that says
#pragma multi_compile __ IS_UNITY_EDITOR
so that the shader variation you want is actually compiled so you can call it at runtime.
Your answer
Follow this Question
Related Questions
(Shader)How to find the cordinate of a given color inside a ramp texture? 0 Answers
Shader shows odd Simplex Noise behavior on Android 0 Answers
Reuse vertices modified in a previous shader pass 1 Answer
how to approach instanceID in shader? 0 Answers
How do you change Point Size in Direct3d 11 shader? 1 Answer