- Home /
Problem is not reproducible or outdated
Trying to change texture in Runtime - it becomes pink?
Hi, I'm trying to make some kind of slideshow in unity, but when I run the code, the object becomes pink. here's the code :-)
public GameObject l;
public Material l1;
public Material l2;
public Material l3;
// Use this for initialization
void Start () {
l = GameObject.Find("Screen");
StartCoroutine ("SwitchImage");
}
public IEnumerator SwitchImage() {
print ("1");
l.renderer.material = l1;
yield return new WaitForSeconds(1f);
print ("2");
l.renderer.material = l2;
yield return new WaitForSeconds(1f);
print ("3");
l.renderer.material = l3;
yield return new WaitForSeconds(1f);
I have asigned everything and there's no errors in the console..
Thanks, Andreas.
EDIT: If I look at the scene while it's at runtime, it seems like there is no texture at all..? just as if I had deleted it.
Does it print 1,2,3? If you select the Screen" object and watch, does the material change?
For fun, test just the new materials: have start just say l.renderer.material = l2;
(and don't call the Coroutine.) Does that work?
Yes it says 1,2,3. I can't see the the material on the object while at runtime(just as if it was deleted), but in the Editor/scene the material works as it should. No it doesn't work even when executing the line in the start void and it's still pink when I run the game..
If it won't work in Start, focus on that. Changing the material in Start, exactly the way you did, works fine for me.
There's probably something else messing up the material. Could try it in a fresh scene by itself.
Okay, it seems like using gameObject.renderer.material = l1; and put the script on the "Screen" fixed the issue, although some other random texture in my game became pink now (straaange) hehe, Thanks for the help :-)
Same issue here and the material is assigned is inspector.
Answer by Bincredible · Apr 07, 2013 at 03:15 AM
Maybe the material or texture you are using is not missing. Because when I have a pink object, it's usually that the material is missing. Make sure that your material is in the inspector and is assigned at all times. :)
Answer by admin_8C · May 29, 2017 at 06:34 AM
They're trying to be helpful for future users, but don't quite realize how a site like this works. Everyone can do a google Search. If the answer that helped you was on the first few pages there's no need to add a link to it. Everyone else will find it the same way you did.
A funny thing is, that link isn't even the answer. Pink means something is wrong with the material or texture or shader. That linked answer is only for when it works fine but then breaks when you Build it (and that's not even the only reason for that.) But they were trying to be helpful.