- Home /
How to get the property names from shader in runtime?
i want to make a transition script for material with same shader. It will be more useful if i don't need to hardcode the property. So... how to get the property names from shader in runtime? Can i use System.Reflection to do that?
Answer by tanoshimi · May 23, 2016 at 11:30 AM
You can't do it directly at runtime, I don't think. Although you can use the ShaderUtil class to enumerate properties of shaders via script, this only works in the editor, not at runtime.
However - there's a workaround - since the list of shaders in the application is fixed at compile-time and can't be modified, it is possible to use ShaderUtil to create a dictionary of properties at compile time, and then just look up those properties from the created dictionary at runtime.
This approach is described in more detail in robertbu's reply at http://answers.unity3d.com/questions/501797/can-i-get-the-a-list-of-the-properties-in-a-shader.html
Answer by See_Sharp · Apr 12, 2016 at 08:34 AM
Select the shader you want:
This menu will popup, displaying all the properties of the shader:
And you can use them in a script like this:
material.SetColor("_Color", Color.black);
material.SetFloat("_BumpScale", 5);
I didn't know an android/iOS app has permission to launch unity editor in my computer and control it. Since when do they have this power? Do i have to plug my phone to the computer with usb cable? or they can control it through wifi. Do you think if i load the game document to my mobile, it will automatically develop the whole game so i only need to do the design job?