Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 cfanpnk · May 26, 2011 at 12:47 AM · collisionrenderer

Making Objects Invisible by Using renderer.enable does not work

Hey guys. I've played around with this for hours. But it still doesn't work.

I try to move some spheres inside a cube. When the spheres collide with cube, it disappears.

 function OnCollisionEnter(collision : Collision)
 {
     if(collision.gameObject.name == "Air Bubble")
     {
         collision.gameObject.renderer.enabled = false;
     }
 }

I think the problem comes from the collision detection. Because when I try to iterate all of them and make their renderer's false. It works. But when I use gameObject.renderer.enabled = false. They will not work. Basically, setting individual object's renderer to false will not work.

Any suggestion on how to solve the detection problem?

Comment
Add comment · Show 3
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 Wolfram · May 26, 2011 at 12:59 AM 0
Share

Have you checked whether this function is called at all? And if it is, is the if()-condition ever met? Add two Debug.Log messages to confirm that.

$$anonymous$$y guess is a problem with the collision detection. Your spheres might be too small and too fast, so they never collide with the cube's shell during frames. Search the Wiki for a script named "DontGoThroughThings"

avatar image cfanpnk · May 26, 2011 at 03:41 AM 0
Share

Thanks. The function is called. I see the debug info. How do I know they are too small or too fast?? They are moving in a speed that I can view. They all have scale(1,1,1). Are they small?

avatar image Wolfram · May 26, 2011 at 11:11 AM 0
Share

Do none of the bubbles disappear, or just some of them? Is the "if" condition above ever met (see my comment, put another Debug.Log in there)? What are the dimensions of your cube as opposed to your spheres? Is the cube a Unity primitive, or is it a model?

If the spheres move to fast (essentially, if in one (physics-)frame they are fully inside the cube, but the next (physics-)frame would put them fully outside), the physics engine doesn't receive any collision events. The "DontGoThroughThings" makes sure these situations are catched.

5 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 26, 2011 at 01:03 AM

Don't rely on the auto-generated name. For example if your cloned object hold a reference to his own prefab, the reference will be changed when he's instantiated. If the clone create another instance it will clone itself instead of the original prefab. The name will be "Air Bubble(clone)(clone)" in that case.

You can either set a fix name when you instantiate the objects, or use a tag name instead of the object name.

example:

 var clone : GameObject;
 clone = Instantiate(prefab);
 clone.name = "Air Bubble";

Another problem could be that if your object have sub objects also with colliders, you can collide with them and you will get the name of this subobject instead.

To check what the problem is you can temporarily put a Debug.Log("Collided with :" + collision.gameObject.name); in your OnCollisionEnter function. It will print the name of the object you just collided with.

Comment
Add comment · Show 8 · 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 cfanpnk · May 26, 2011 at 03:22 AM 0
Share

Thank you for your answer. I tried everything......it still doesn't work. I tried to rename all the clone objects as you said. Only 1 or 2 of the clone objects' renderer set to false.

avatar image cfanpnk · May 26, 2011 at 03:23 AM 0
Share

BTW, i also used the debug info. It does display the correct collision info.

avatar image cfanpnk · May 26, 2011 at 03:32 AM 0
Share

It displays 7 collision info...but only 3 air bubbles disappear. can't figure out why...have worked on it the whole day...

avatar image Bunny83 · May 26, 2011 at 03:52 AM 0
Share

If the renderer gets disabled it should disappear. Are you sure that you don't enable it somewhere else? Remember, you can pause the game with the pause button at the side of the play button. Then you can check the renderer state of your objects and other stuff.

All those "bubbles" are instantiated from the same prefab, right? Or do you have different types/prefabs?

avatar image cfanpnk · May 26, 2011 at 04:05 AM 0
Share

I used the pause button. That's how i know only 1 or 2 of them are set to false. All those bubbles are instantiated from one prefab.

Show more comments
avatar image
0

Answer by hastenshawn · May 26, 2011 at 01:14 AM

one problem i believe your having here is that your using air bubble(clone) this has caused me problems myself but you can fix this by using tags you could use airbubble = GameObject.FindGameObjectWithTag("yourtag"); and then after doing that in your OnCollisionEnter(collision : Collision) change that to OnTriggerEnter so then it should look like this:


var airbubble : GameObject;

 function OnTriggerEnter (hit : Collider)
 {
     airbubble = GameObject.FindGameObjectWithTag("airbubble");   

 
     if(hit.gameObject == airbubble)
     {
         hit.gameObject.renderer.enabled = false;
     }
 }



i've tested this i know that this works

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 cfanpnk · May 26, 2011 at 01:54 AM 0
Share

Thanks for answering my question. I've tried to use tags before I asked the question. And it still doesn't work. I don't understand why you choose OnTriggerEnter ins$$anonymous$$d though it doesn't work either.

avatar image Bunny83 · May 26, 2011 at 02:35 AM 0
Share

Sorry, but your example doesn't make much sense. FindGameObjectWithTag will find only the first gameobject with that tag. If you collide with another bubble it won't work. You should compare the tag name of the object you hit.

if (hit.gameObject.tag == "airbubble")

also i don't see any reason why you should use a trigger ins$$anonymous$$d of a normal collider. If it's a rigidbody you can't turn the collider into a trigger.

avatar image
0

Answer by ccraig · Apr 10, 2013 at 12:06 PM

take out the gameobjects.

 function OnCollisionEnter(collision : Collision)
 {
     if(collision.renderer.name == "Air Bubble")
     {
        collision.renderer.enabled = false;
     }
 }
 
 I use c#, but this looks right to me.
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 volkswagenb · Jul 17, 2013 at 07:06 PM

Hope this helps somebody:

  track.renderer.enabled=false; //didn't work
 
  //I had to use:    
  track.renderer.active=false;  //this worked

I've been trying unity for a couple months now, but I'm getting tired of it. I'm hammering on just because they deal with the low level 3D-hardware startup.

Comment
Add comment · Show 1 · 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 hunterruth · Apr 05, 2014 at 04:13 AM 0
Share

This worked for me. Thanks, Volkswagenb!

avatar image
0

Answer by acoleman · Aug 20, 2014 at 10:13 PM

What I had to do was restart Unity and now it works.

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

How to check of a line renderer collides with ground ? 1 Answer

How to make an object appear after collision with an invisible object. I have tried a lot of ways, but still failed please help! 1 Answer

Unable to disable collider2d and renderer of gameobject. 1 Answer

How to make work a collision when is invisible? 3 Answers

How to change the material color of an Instatiated prefab when the player enters the collision area and presses a button? 0 Answers


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