• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by eXKR · Nov 19, 2009 at 11:19 PM · gameobject

How to hide just one mesh (meshfilter) from a gameObject that has 2 meshes?

We already know that it's possible to hide or deactivate a mesh using:

GetComponent(MeshRenderer).enabled = false;

but, what if the gameObject has 2 or more meshes and we want to just hide one of them? Imagine this structure: gameObject mesh1 mesh2 mesh3

How to access mesh2 and deactivate it?

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Kiyaku · Nov 19, 2009 at 11:48 PM

Well i think it is not even possible to use more than one MeshRenderer on the same object, same for MeshFilter.

And i think i never see more than one mesh applied to a MeshFilter on any model of mine. If i have several meshes in one Model, it will be seperated into Parents. Then you can just hide the parents if you need to.

For example if you want to make an MMO and customize your model, you could include all kind of jackets into one model. If you then want to display only the "naked" version, just make the parent "naked" visible and everything else invisible (like "robe", "t-shirt", whatever) (just an example, there are probably better solutions).

If this doesn't help, maybe it would help to know what exactly you want to do.

EDIT:

You could use a function lide to to show only the mesh you enter in the "showExcept":

void Start () { showExcept("mesh1"); }

void showExcept(string meshName) { foreach(Transform temp in transform) { if(temp.name == meshName) temp.renderer.enabled = true; else temp.renderer.enabled = false; } }

So in this case, only "mesh1" will be displayed, everything else will be invisible. you could write several function (to activate only one mesh without deactivating the others, activate everything except one, etc).

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image eXKR · Nov 20, 2009 at 08:36 AM 0
Share

Your example could work for me, but my problem is that I don't know how to code it... So, for example, with the hierarchy I proposed (house/mesh1) how can I deactivate "mesh1" without deactivating "house"? Thanks

avatar image Kiyaku · Nov 20, 2009 at 09:47 AM 0
Share

edited my post with a code that could help you

avatar image
1

Answer by eXKR · Nov 23, 2009 at 07:49 AM

I finally got what I wanted:

// This script is made to be applied to an unique gameObject that has 3 different meshes called HLOD, MLOD and LLOD that will correspond with its different versions.

var distance1 = 5.0; //Jump from HLOD to MLOD var distance2 = 10.0; //Jump from MLOD to LLOD private var HLOD : Transform; private var MLOD : Transform; private var LLOD : Transform;

function Start() { HLOD = transform.Find("HLOD"); MLOD = transform.Find("MLOD"); LLOD = transform.Find("LLOD"); } function Update () { //The camera should have applied "MainCamera" tag in order to correctly switch LODs var campos = Camera.main.transform.position;

 if ((transform.position - campos).sqrMagnitude < distance1 * distance1 )
 {
     // use High LOD
     HLOD.active = true;
     MLOD.active = false;
     LLOD.active = false;
 }

else if ((transform.position - campos).sqrMagnitude < distance2 * distance2) { // use Medium LOD HLOD.active = false; MLOD.active = true; LLOD.active = false; } else { // use Low LOD HLOD.active = false; MLOD.active = false; LLOD.active = true; } }

This code worked like a charm for me. Thank you very much for your help.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Lucas Meijer 1 · Nov 20, 2009 at 08:30 AM

If they have different materials, you could change the material to not render anything, however it seems it would make a lot more sense to actually use three gameobjects if you need to do this.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Unity Editor Scripts: GameObject Added / Removed Event? 1 Answer

Souls pickup mechanic (Like Dark Souls, BloodBourne) 0 Answers

How to create 3D game object in specified pixel size? 2 Answers

How to get info of object within certain range?(Javascript) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges