- Home /
How to force a texture to be included in an iOS Project?
First time building and running my Unity3D app on my iPhone and it appears that all the textures are missing. Everything is just a solid block of whatever color I made it. When running in Unity I see everything correctly. See images...
I am using custom shaders, and all the objects are custom procedural meshes. Many many quads that I build in script. In my paper backplate inspector you can see that on the material I don't have the texture linked. Instead I have it linked on the main script and then I assign that texture to the material in Awake.
void Awake ()
{
meshFilterComponent = GetComponent<MeshFilter>();
Material material = GetComponent<MeshRenderer>().material;
material.SetTexture(0, paperTexture);
material.color = new Vector4(1f, 1f, 1f, 1f);
}
When I hit play the script runs and the texture in the inspector changes from None to the paper texture. The mesh gets built in the script. Everything renders fine. But when I run it on the iPhone I suspect that it's not finding that paperTexture in the assets. It renders the quad all white. If I pre-link the Texture to the paper texture and then build it on the phone the texture renders correctly on the phone. But that doesn't work for me because in other cases (not this paper background) I need to be able to pick the appropriate texture programmatically. For example if I were to have skin-able themes or something.
Any clue why the texture wouldn't already be part of the project in iOS when it is linked to the Paper Texture property of the PaperBackplate script? Or why that would only be a problem on iOS and not when run in the unity interface.
Is there a way to make sure that a texture is going to be part of a project? Also where in the iOS project in Xcode do you find assets like textures? I'm not seeing them in the Xcode project anywhere even when it does render with the texture.
UPDATE
I changed my texture folder to "Resources" but that didn't fix it.
Is there anywhere where you load it differently? For example, just renderer.material=
If the paper texture is in a public script var, it should be in the build. I'm wondering if something funny is going on with the assignment ($$anonymous$$aterials like to secretly give you cloned instances.)
Aren't I doing render.material= in my awake method? I do want instances of my material so I can have different textures on each one.
I did try assigning it in the inspector and it does work that way. So as you say it's not the shader. I'm doing set texture 0 right now. In the morning I'll try it the way you suggest. Thanks for the advice.
@Neamtzu, That fixed it. Write it as an answer so I can checkmark it.
What? Your screenshot clearly shows paperTexture
was assigned in the Inspector, in the paperBackplate script.
Answer by Neamtzu · Mar 02, 2015 at 11:20 AM
Try to make a build with the textures assigned from the inspector. If it doesn't work, the problem is caused by the shaders. If it works, the problem is the assignment.
Btw, try to assign the texture like this: material.SetTexture("yourVariableName", bumpMap); - where yourVariableName is the name of the texture in shader.