Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 Ardtrav · Feb 22, 2013 at 03:29 AM · objectdisappearanimated

How to make an animated object disappear?

Hello, I'm very new in Unity,just started exploring bits here and there. I'm trying to make an object that disappears after it has finished animating. Okay,here is the scenario: An inanimate object(lets say a cube) is collided with another object,it then animates in a certain way,after it finishes the animation it disappears. How to do that? I'v so far only stumble upon these renderable thingy,i think i have to make the animated cube invisible,while the station cube visible,when the visible cube is triggered or touched it becomes invisible or renderable=false and the animated cube visible(renderable=true). But after it animates how to make it disappear? Thank you for the help

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

2 Replies

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

Answer by aldonaletto · Feb 22, 2013 at 03:57 AM

You could deactivate the object with SetActive:

 gameObject.SetActive(false);

This is better than just setting renderer.enabled to false, because all components (colliders, scripts etc.) and children of this object are deactivated as well - you'll not have problems with an invisible object haunting the scene.

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 Ardtrav · Feb 22, 2013 at 12:20 PM 0
Share

First of all thanks mr Aldo :) Hm,SetActive(),cool approach,i'll try that. However that will just deactivate the animation of the object right?I want it to totally disappear after it finishes animating.Or else im gonna have to manually animate it to scale to 0,0,0 heh.

avatar image aldonaletto · Feb 24, 2013 at 08:30 PM 1
Share

No, SetActive is a GameObject method that activates/deactivates the whole object - the object and all of its children just disappear from the scene, as if it was destroyed.

But I think you don't need inanimate and animated objects: the same object could have an animation - when colliding with something, the object could start playing its animation and deactivate itself after the appropriate delay, like this:

 private var collided = false;

 function OnCollisionEnter(){
   if (!collided){
     collided = true;
     StartCoroutine(PlayAndDisappear());
   }
 }
 
 // play and disappear after delay:
 function PlayAndDisappear(){
   animation.Play("someAnimation");
   WaitForSeconds(animation["someAnimation"].length);
   gameObject.SetActive(false); // deactivate object
 }

NOTE: The object must be a rigidbody to generate OnCollision events when hitting another collider

avatar image
0

Answer by OmahaNS · Feb 22, 2013 at 02:47 PM

This depends on your desired behaviour. If you want it to be invisible but still interact with your scene, set renderer.enabled to false. If you want it gone completely, call Destroy(gameObject). If you want to disable it to re-enable it later, use gameObject.SetActive(false), or if it has children, gameObject.SetActiveRecursively(false).

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 Ardtrav · Mar 12, 2013 at 11:27 PM 0
Share

Thanks,OmahaNS,this helped too :)

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

11 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

Related Questions

How would I make an object disappear after a set amount of time? 3 Answers

Make a game object disappear when your camera looks at it. 1 Answer

object name disappearing!! 1 Answer

Object dissapearing, but renderer shows true 1 Answer

Object vanishes when becoming a child 2 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