Textures are pink on iOS Build
I've been having trouble with and GoogleVR app on an iOS device.
My first issue was a null pointer error. This happened while in XCode but not in Unity (EXC_BAD_ACCESS code = 1) I fixed this after looking around in the API documentation on the "Create Primitive" function, specifically the part where it will crash.
CreatePrimitive may fail at runtime. This will happen if your project does not reference the following components: MeshFilter, MeshRenderer, and BoxCollider or SphereCollider at runtime.
So I added all of those elements to each GameObject (even though Unity told me in the Editor they already those components.)
Also, keep in mind this works perfectly on Andriod builds, where those additional objects are implied in comparison to iOS. (I assume? If anyone could provide a more technical/correct explanation that would be lovely.)
Nevertheless, finally, I had no crashing when installing to the iOS device! Yay! ...But pink textures. Boo!
So I've tried several things: First I tried changing the color by accessing the material in MeshRenderer and changing it to the appropriate color; that didn't work. Then I tried doing the original way by accessing the Renderer component and setting the material to the desired color; that didnt work either. Finally, when looking around at some of the questions I found one possible solution which was setting the Built-in shader "Deferred" from "Built-In Shader" to "No Support"; and alas that did not work either.
So I'm quite at a loss here and I would like to keep everything as self-contained as possible i.e. all in one script, such as the one below. If anyone could be kind enough to provide a solution or probe me for more detail, I would be very grateful. Also, if anyone is curious, the image is just supposed to be a ball-and-stick representation for a water molecule.
using UnityEngine;
using System.Collections;
/***********************/
//Drawing a water molecule
/***********************/
public class water : MonoBehaviour
{
// Use this for initialization
void Start()
{
GameObject[] atoms;
float[] covalRadii = { 0.37f,0.73f};
//First create each atom as a sphere using XYZ coordinates
GameObject h1 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
h1.AddComponent<MeshFilter>();
h1.AddComponent<MeshRenderer>();
h1.AddComponent<SphereCollider>();
GameObject h2 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
h2.AddComponent<MeshFilter>();
h2.AddComponent<MeshRenderer>();
h2.AddComponent<SphereCollider>();
GameObject o1 = GameObject.CreatePrimitive(PrimitiveType.Sphere);
o1.AddComponent<MeshFilter>();
o1.AddComponent<MeshRenderer>();
o1.AddComponent<SphereCollider>();
//Then set their positions
h1.transform.position = new Vector3(0.96f, 0.0f, -0.27f);
h2.transform.position = new Vector3(0.0f, 0.0f, 1.0f);
o1.transform.position = new Vector3(0.0f, 0.0f, 0.0f);
//Set size
h1.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
h2.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
o1.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
//Now tag each one with the index number corresponding to the values in covalRadii
h1.gameObject.tag = "0";
h2.gameObject.tag = "0";
o1.gameObject.tag = "1";
//Color each atom
h1.GetComponent<Renderer> ().material.color = Color.white;
h2.GetComponent<Renderer> ().material.color = Color.white;
o1.GetComponent<Renderer> ().material.color = Color.red;
//Finally, store them in the array
atoms = new GameObject[3] { h1, h2, o1 };
//Now to find the bonds
for(int i = 0; i < atoms.Length; i++)
{
for(int k = i + 1; k < atoms.Length; k++)
{
float distance = Vector3.Distance(atoms[i].transform.position, atoms[k].transform.position);
float sum = covalRadii[int.Parse(atoms[i].tag)] + covalRadii[int.Parse(atoms[k].tag)];
if (distance <= sum)
{
GameObject cyl = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
cyl.transform.position = atoms[k].transform.position - atoms[i].transform.position / 2.0f + atoms[i].transform.position;
Vector3 v3T = cyl.transform.localScale; // Scale it
v3T.y = (atoms[k].transform.position - atoms[i].transform.position).magnitude;
cyl.transform.localScale = new Vector3(0.1f,0.5f,0.1f);
cyl.transform.rotation = Quaternion.FromToRotation(Vector3.up, (atoms[k].transform.position - atoms[i].transform.position));
}
}
}
}
}
Unity: 5.5.0f3 Mac: 10.12.2 iOS Software: 10.2