- Home /
Material rendering black in iOS and Android when assigned in code.
Hi,
I have an array of materials and when I assign one to a plane it's displayed black. This happens only in devices, not on web. The materials are power of 2, and if I assign it in the editor it shows up well in the devices.
Here's my code:
var tarjetas : Material[];
function Start ()
{
transform.Find("Front").renderer.material = tarjetas[0];
}
It should be noted that this script is applied to an empty GameObject that has two planes in it (Front and Back);
Any help will be much appreciated. Thanks!
As a starting point, try an alternate shader. I know I've had issues with even simple shaders working in one environment and not in others.
You will often see shader errors appearing in the device log if the shader would not compile on the device
There were no shader errors in the log. Only if I assign them in code they appear black.
The log on the device? And have you tried a different shader to rule out the textures etc. Pretty sure my iOS shaders go black if they don't compile - but Unity always puts a log in the XCode console explaining why.
You might want to try have something with that shader on it actually in the scene - there might be a problem where it gets optimised out of the build if nothing appears to be using it.
Answer by Goodgab · Mar 29, 2013 at 12:16 AM
Turned out the z property of scale in my plane was 0! Changing it to 1 solved the problem.
strange how it worked with the web player and simulator but not the devices...
Answer by KBAallstar · Jul 13, 2015 at 11:57 PM
I had issues with basic materials turning black on Android. Fixed it by reducing the "smoothness" of the material to 0.5 or less. I also chose compress in ETC1 format, but I think the main issue was smoothness above 0.5. I'm using Unity 5.1.