Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kain Mikado · Oct 04, 2010 at 05:03 AM · destroyinstanceclone

How do I properly destroy an instance of a prefab from within its own script?

Here's the setup: I have a platform, this platform is attached to a blank GameObject called Pusher with an animation and script component. That is to say the empty 'container' object has the animation and script components as well as the child 'platform'.

Pusher is designed to push a few blocks sitting on it up, then create a new instance of itself (along with a few more blocks right under the previous blocks), then delete itself. The new instance does the same thing until I tell this whole process to stop.

The whole thing works great. The only problem is in my editor, in the Heirarchy View, next to the 'Pusher' prefab I see (clone)(clone)(clone)... for as many times as this process has repeated itself. I imagine it has something to do with not completely deleting itself. Again, it works aside from that being, what I can only imagine, a massive memory issue. I've listed the code below; any help would be fantastic.

void CreateNewPusher() {
    this.isAtTop = false;
    Instantiate(this.pusherPrefab, this.originPoint, this.transform.rotation);
    GameObject.Find("Block Factory").GetComponent<BlockFactory>().CreateNewLine();
    Destroy(this.gameObject);
}

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
2
Best Answer

Answer by Adam Rademacher · Oct 04, 2010 at 05:35 AM

You can get around this by reassigning the name on instantiation...It's nothing to do with the objects not deleting themselves, they're just cloning themselves before they get destroyed again, adding an additional (clone) to the end each time.

void CreateNewPusher() {
this.isAtTop = false;
GameObject newPusher = (GameObject)Instantiate(this.pusherPrefab, this.originPoint, this.transform.rotation);
newPusher.name = "Pusher";
GameObject.Find("Block Factory").GetComponent<BlockFactory>().CreateNewLine();
Destroy(this.gameObject);
}
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 Kain Mikado · Oct 04, 2010 at 04:36 PM 0
Share

That worked great! So it's not that there were ever multiple instances, just that the name kept getting the (clone) appended to the end; that does answer why the (clone)s were all on the same 'object' rather than making the list longer. Thank you!!

avatar image Frank-Grimes · Jun 22, 2015 at 04:52 AM 0
Share

thanks man!

avatar image Arju2011 Frank-Grimes · Dec 06, 2015 at 08:36 AM 0
Share

Comments are not supposed to go in the answer section.

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

2 People are following this question.

avatar image avatar image

Related Questions

Destroy instance clone of gameobject 2 Answers

Duplicate Object, by dragging? (SporeCreatureCreator Like) 0 Answers

How to destroy gun bullet clone? 1 Answer

How do I assign a script to a clone through another script? 1 Answer

destroy child object 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