- Home /
MeshRender Enabling.
I have been searching a little while to see if this is possible but have come up with nothing. Aside from Enabling and disabling the whole component on the GameObject.
Is there a way to enable and disable Various Elements in a MeshRender on a GameObject by script. For instance Enabling Element 1 and disabling all other elements.
Thank you for your time.
(Also could say I want to enable and disable a lot of materials on one object.)
Answer by Zergling103 · Dec 20, 2011 at 01:11 AM
So you want to disable the rendering of submeshes?
Meshes usually contain multiple materials, and for each material there is a submesh to go with it. (The technical reason for this is you cannot switch materials in one render call, and each render call should recieve all the mesh data to be rendered with that material. So its stored in a submesh and sent individually.)
Sometimes when you import a mesh, it is stored as a prefab with the submeshes stored as children of that prefab. Each child will have it's own MeshRenderer. You can disable that. Otherwise you might be able to drag out individual submeshes from the prefab and initialize them separately, giving each it's own renderer which you can disable.
If they cannot be separated then as far as I am aware you cannot disable submesh rendering individually. The model will have to be re-exported per material.
If the mesh is skinned, then I'd recommend finding a work-around that doesn't require disabling per-material rendering.
I cannot recommend writing a shader that renders the object as fully transparent as an alternative to disabling the render altogether as this is very amateurish and a waste of rendering power.
Both of your answer worked. After reading what Lo0Hnuit$$anonymous$$ linked I managed to work out what I wanted to do. And I do appreciate your detailed explanation and answer Zergling. Thanks
Your answer
Follow this Question
Related Questions
Fade an object in and out 0 Answers
Why isn't the color changing? 1 Answer
Disable Meshrenderer OnTriggerEnter 0 Answers
How to make a cube with metallic look and soft edges [pic included] 1 Answer