- Home /
Texture2D not showing in build, but shows up in editor
I have a Texture2D that I pass to a GUI.Box that shows up in the editor but not when I run the build standalone version.
Code:
style.normal.background = m_LeftFootBoxTexture;
GUI.Box(new Rect(Screen.width - 375, leftFootBoxHeight, 50, 25 ), "L", style);
style.normal.background = m_RightFootBoxTexture;
GUI.Box(new Rect(Screen.width - 325, rightFootBoxHeight, 50, 25 ), "R", style);
I have tried to pass the textures directly, like so:
GUI.Box(new Rect(Screen.width - 475, leftFootBoxHeight, 50, 25), m_LeftFootBoxTexture);
GUI.Box(new Rect(Screen.width - 425, rightFootBoxHeight, 50, 25), m_RightFootBoxTexture);
This made no difference.
The textures and style are created in the Start() method.
m_LeftFootBoxTexture = new Texture2D(1, 1);
m_RightFootBoxTexture = new Texture2D(1, 1);
style = new GUIStyle();
I change the color for each pass. Like so:
m_LeftFootBoxTexture.SetPixel(0, 0, m_LeftBoxColor);
m_RightFootBoxTexture.SetPixel(0, 0, m_RightBoxColor);
Does anyone have any clue as to what could cause this?
Just a thought, Screen.width might be different between editor and standalone.
And what's leftFootBoxHeight?
Just a thought, Screen.width might be different between editor and standalone. And what's leftFootBoxHeight?
Good thought, but I forgot to mention that the content of the boxes ("L" and "R") actually show up where I want it to but it contains not color, so it has nothing to do with the position.
Try m_LeftFootBoxTexture.Apply() and m_RightFootBoxTexture.Apply() after you initialize the textures. You might want to also add those right below you finish modifying them with SetPixel.
Thanks, this worked! It worked after I added the Apply() method calls after modifying them with SetPixel().
Answer by Professor Snake · Nov 04, 2013 at 04:48 PM
Try m_LeftFootBoxTexture.Apply() and m_RightFootBoxTexture.Apply() after you initialize the textures. You might want to also add those right below you finish modifying them with SetPixel.