- Home /
My Dynamically create Textures are showing up white until i play with the inspector
Hello I have an odd problem,
I am creating players for a soccer game with dynamically created textures for jumpers
When they get created the Texture shows as white, but if i tick and untick the "enable Detail texture" flag it renders fine showing that the texture was created properly, (Pictures below to explain further)
I assume a redraw call gets made when you fiddle with the inspector but i'm unsure how to leverage that.
Thanks for reading, any advice is greatly appreciated :D

Answer by Eno-Khaon · Feb 11, 2019 at 05:07 AM
I'm not very familiar with the shader you're using, but an initial look around online suggests that it is multi-compiled to use two variants with the Detail Texture enabled or disabled.
Based on that, because you're toggling that shader flag back to "on" it updates which variant of the shader it's using.
With all of this in mind, you should be able to solve your problem at the same time you assign the procedural Texture to the Material by enabling the Keyword in the shader.
// When you assign the Texture to the Material...
// I don't know what yours looks like, so here's an
// approximate guess.
myMaterial.mainTexture = myNewTexture;
// Then, to tell the Material that you want to use it,
// assuming you're using the shader I came across...
myMaterial.EnableKeyword("_TEX_ON");
Thank you so much for your quick reply, Worked perfectly!!! i have added the snippet below just in case anyone else has the issue i had.
Debug.Log("Create a jumper");
GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.position = new Vector3(0,0, 0);
cube.GetComponentInChildren<Renderer>().material = make$$anonymous$$at(pname,number);
cube.GetComponentInChildren<$$anonymous$$eshRenderer>().material.Enable$$anonymous$$eyword("_TEX_ON");
Thanks again!!
Happy to help out.
If I may offer another idea while we're at it, $$anonymous$$eshRenderer inherits from Renderer, so you can also cut out a GetComponent<> call here.
$$anonymous$$eshRenderer mr = cube.GetComponentInChildren<$$anonymous$$eshRenderer>();
mr.material = make$$anonymous$$at(pname,number);
mr.material.Enable$$anonymous$$eyword("_TEX_ON");
In fact, you could even potentially condense that down slightly more, as well:
$$anonymous$$aterial mat = make$$anonymous$$at(pname,number);
mat.Enable$$anonymous$$eyword("_TEX_ON");
cube.GetComponentInChildren<$$anonymous$$eshRenderer>().material = mat;
Answer by unity_107801B5E237A5D0D25D · Jan 28 at 10:04 AM
Hello this is happening when we change the texture of the 2d raw image it is displaying white, if anything changing then it is displaying. what should be going when this happens in 2d Raw image texture change? Thanks
Your answer
