- Home /
Enable MeshRenderer from all objects in array
Hello everyone,
I've been searching for a solution for my problem on the web, and posted this question about it, but as far as I tried now, there aren't any solutions yet. I have an array of gameobjects colorStamps, with their Meshrenderers disabled by default. When my player gets a specific pickup, the "ShowPath()" function is being called and the MeshRenderers from all the colorStamp gameobjects in the array should enable. In the Unity Editor it works like a charm, but when I build to iOS, the meshes don't show/ stay disabled.
Code (CSharp):
public void ShowPath() { colorStamps = GameObject.FindGameObjectsWithTag("PathBlocks");
for (int i = 0; i < colorStamps.Length; i++)
{
TheMesh = colorStamps[i].gameObject.GetComponent<MeshRenderer>() as MeshRenderer;
TheMesh.enabled = true;
}
I've read that the GetComponent could return a component, instead of an MeshRenderer, so I already tried the 'as MeshRenderer' at the end of the declaration line. I tried with and without. Also, I've read that in iOS, the 'shortcut' for GetComponent().enable could give problems, but separating them didn't fix it either. Last but not least, yes, the colorStamps objects are tagged with the PathBlocks tag and the colorStamps GameObject[] is declared on top of the script. Plus, yeah, it does work in the editor, so it has to be something in the conversion to iOS? What am I doing wrong? Thanks for your help!
Answer by sameel · Jan 09, 2017 at 08:41 AM
@elmidiachi, Use this instead.
for (int i = 0; i < colorStamps.Length; i++)
{
colorStamps[i].gameObject.GetComponent<MeshRenderer>().enabled = true;
}
Thanks for your reply. That was the first option I tried. But it doesn't work on iOS. Still working in the Unity Editor...
If its working in unity editor then it should work on ios iOs too.
yeah! That's what I thought... But nope. The meshes aren't being enabled after the pickUp. Strange eh? I'm building to iOS on my i$$anonymous$$ac, using Xcode 8.2.1 and running on iOS 10.2, iPhone 7.
No solution yet :( I made a new comment, But its still in moderation. Thanks already though!
@sameel!! thank you sooo much! I really don't understand what was going on. I created a new prefab from the original object and now it works in the editor and in iOS!! This is really weird... But hell yes, it works :) Thanks for your help and finding that post!
Your answer
![](https://koobas.hobune.stream/wayback/20220612104331im_/https://answers.unity.com/themes/thub/images/avi.jpg)