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 Essential · Apr 04, 2013 at 03:51 AM · destroyawake

Destroy object before end of Awake function

I'm trying to destroy an object in Awake but if I use the Destroy(gameObject) call, it will continue running the code in the Awake function until the end. How can I destroy it immediately and not run anymore code from that point?

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

Answer by whydoidoit · Apr 04, 2013 at 04:17 AM

You just need to "return" after you've destroyed it. It will also continue to exist for that frame unless you use DestroyImmediate.

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 Essential · Apr 04, 2013 at 04:28 AM 0
Share

Hmm… I saw DestroyImmediate but the documentation is very specific of warning people away from using that in game code.

Is it safe?

avatar image Essential · Apr 04, 2013 at 04:59 AM 0
Share

Just saw this comment from Eric on this question, kinda gives me the info I was looking for: http://answers.unity3d.com/questions/18651/Difference-between-Destroy-and-DestroyImmediate-.html

I wish there was a little more info in the documentation of WHY they warn against it though, just so I can be careful of its use.

avatar image whydoidoit · Apr 04, 2013 at 11:27 AM 0
Share

It's reasonably safe so long as you know what you are doing. The idea is that in a frame all of the objects should exist because perhaps there's some interaction going on between scripts, it might screw up physics if you did it in there for instance, not sure. I use it without a problem when necessary, but only do it when I must.

avatar image Essential · Apr 08, 2013 at 08:02 PM 0
Share

I just tested this and DestroyImmediate isn't as immediate as I need it to be. It's still continuing to stay alive so that other objects can Find it. :(

I guess I'll have to re-work my code to figure out another way to make this work…

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

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

Destroy an enemy when it touches an object 2 Answers

Destroying an object when it collides with another 1 Answer

Instantiate JS error that i can't figure out 1 Answer

destroy a non-trigger object hitting a trigger object? 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