Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 raycosantana · Oct 28, 2013 at 06:05 PM · meshruntimemesh renderer

disabling Mesh renderer on runtime.

I want to turn the mesh renderer off on runtime but for some reason the mesh renderer gets disabled but the object still can be seen; I tried turning the component itself off and also tried turning the renderer of (renderer.enable = false;)

Here is the script Im using, it disables the renderer depending of how far the Player is, I have a similar script for turning lights off that works perfectly

 using UnityEngine;
 using System.Collections;
 
 public class Betolder : MonoBehaviour {
     public float availableDistance;
     private float Distance;
 
     ///------------------------------
 
      
     // Update is called once per frame
     void Update () {
     GameObject Player = GameObject.FindGameObjectWithTag("Player");
     MeshRenderer MeshComponent = gameObject.GetComponent<MeshRenderer>();
     Distance = Vector3.Distance(Player.transform.position, transform.position);
 
 
         if (Distance < availableDistance){
         renderer.enabled = true;    
         }
         if (Distance > availableDistance){
         renderer.enabled = false;
                 }
     }
     
 }

This one works too, the Mesh renderer gets disabled but the object still there like nothing happened, is weird because If I turn the Mesh renderer off in the editor the object its not rendered at all so I dont understand why I cant do the same thing on runtime.

![alt text][1]

weid thing.jpg (468.5 kB)
weid thing.jpg (468.5 kB)
Comment
Add comment · Show 15
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 sethuraj · Oct 28, 2013 at 06:20 PM 0
Share

works fine for me...

avatar image raycosantana · Oct 28, 2013 at 06:24 PM 0
Share

well, it should, thats why its weird, theres nothing wrong with the script (as far as I know) but the object still gets rendered.

avatar image Dave-Carlile · Oct 28, 2013 at 06:28 PM 0
Share

What does it look like in the inspector while the game is running? Is the renderer disabled? Is there something else enabling it?

avatar image Dave-Carlile · Oct 28, 2013 at 06:37 PM 0
Share

That does look weird. What if you toggle it back on and off in the inspector while the game is running - does it disappear then?

avatar image raycosantana · Oct 28, 2013 at 06:39 PM 0
Share

check out the image I just uploaded, you can see it is off in the inspector but the object still perfectly visible. There nothing turning it on.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by felixpk · Nov 14, 2013 at 02:09 PM

Try gameObject.GetComponentInChildren>Renderer<().enabled = false;

(Inverse these: "") for some reason the code disapears if I write this.

Comment
Add comment · Show 3 · 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 pinder · May 28, 2014 at 06:25 AM 0
Share

felixpk's anwser is very helpful for me. Thanks!

avatar image HalversonS · Apr 25, 2016 at 04:33 PM 0
Share
 gameObject.GetComponentInChildren<Renderer>().enabled = false;

Format it with "Code Sample" then it doesn't remove them.

avatar image drewjosh · Oct 29, 2020 at 08:51 PM 0
Share

Can somebody tell me why this isn't working inside the Start() $$anonymous$$ethod?

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.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite.Create() with outline tolerance? 1 Answer

Seing through triangles in runtime edited mesh 0 Answers

Objects Not Visible In Low End Computer. (Shader Error) 1 Answer

Runtime generated mesh is not shaded right,only grey? 1 Answer

Add Detail Mesh at runtime 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