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
1
Question by Olie · Mar 24, 2010 at 05:07 AM · gameobjecttransformdestroy

How to destroy a transform's parent object.

I'm doing the 3D Platformer tutorial.

I've got my CopperDead prefab, which is an entire dead copper model, but instantiated as a transform in the EnemyDamage.js script, here:

    var deadModel = Instantiate(deadModelPrefab, transform.position, transform.rotation);

Onto my CopperDead prefab, I've added a new script, FadeOutAndDie.js. My goal is to not have the place littered with dead cops but, rather, for them to alpha-fade out, then be destroyed.

...Except I'm not allowed to

Destroy(gameObject);

since that points to a transform, at this point in time. So I tried doing

Destroy ((gameObject as Transform).parent);

but I get a null-pointer error (which is a bit confusing, but that's another question for after I've done more reading.)

So my question is: what's the thing I want to Destroy to get rid of the [dead] robot whose transform I happen to have in my gameObject variable?

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

1 Reply

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

Answer by Olie · Mar 24, 2010 at 05:16 AM

Ok, well... that was dumb. It turns out that all needed to do was change...

var deadModelPrefab : Transform;
var deadModel = Instantiate(deadModelPrefab, transform.position, transform.rotation);

to

var deadModelPrefab : GameObject;
var deadModel = Instantiate(deadModelPrefab, transform.position, transform.rotation);

D'oh! Then, in my FadeOutAndDie.js,

Destroy(gameObject);

works just fine.

Sorry about the dumb n00b question -- seems you always find the answer 10 sec after typing the question & hitting send, eh?

Comment
Add comment · Show 4 · 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 Lipis · Mar 24, 2010 at 10:02 AM 0
Share

Not exactly always.. but next time give it a shot before asking a question if you are about to answer it in 10 seconds.. :)

avatar image Lipis · Mar 24, 2010 at 10:02 AM 0
Share

http://answers.unity3d.com/faq feel free to read that also..!!

avatar image Olie · Mar 24, 2010 at 05:57 PM 0
Share

@Lipis: well, I didn't $$anonymous$$NOW I was going to think of something to try 10 $$anonymous$$utes later, or I would've tried it first! :)

Also, the more abstract question -- how do you find the parent GameObject to which a transform is tied -- still seems like it would be useful. There may be other instances where that crops up, no? It seemed odd to me that someTransform.parent didn't return what I expected. I imagine I'm not the only person just starting with Unity3D who doesn't understand that...

avatar image runevision ♦♦ · Mar 25, 2010 at 04:52 PM 0
Share

@Olie: No need to apologize - it's cool that you came back and answered your own question. After a little while UnityAnswers will allow you to mark your own answer as accepted (click the check mark) so remember to do that! :)

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

No one has followed this question yet.

Related Questions

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

Remove an object from an array and destroy it (C#) 2 Answers

Coding Gui Text To Perform After GameObject Destroy? 1 Answer

Attach Transform to another GameObject 0 Answers

destroying game object in a specific transform 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