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 /
This question was closed Jun 20, 2014 at 03:07 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by youngapprentice · Jun 19, 2014 at 10:10 PM · destroycube

Destroying One Object Destroys Another?

Hi, all!

I have two cubes, and when they occupy the same space in 2D, an event is triggered that mixes their colors together, assigns the color to the first cube, and destroys the second cube.

However, when I destroy the second cube, the first goes with it, and vice versa!

I am confused as to why this is happening.

I can say that they are carrying the same scripts, and each contain instances of a class called CubeData that is on the script ColorCube, which is also a member of each cube. They also share the same parent.

What's up?

Thanks! - YA

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

  • Sort: 
avatar image
0
Best Answer

Answer by IvovdMarel · Jun 19, 2014 at 10:16 PM

Where's the destroy-method called? Did you Debug.Log it to check if it was maybe called twice? (e.g. in both blocks).

The error is in your code, this is no standard behaviour

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 youngapprentice · Jun 19, 2014 at 10:34 PM 0
Share

The Destroy method is called on a parent object that carries out the 'fusion' function. It takes two parameters- The first cube and the second cube. The function works changes on the first cube, and then explicitly deletes only the gameObject that is passed as a parameter in the second slot (The second cube)...

avatar image youngapprentice · Jun 19, 2014 at 10:37 PM 0
Share

I Figured it out. Both cubes are calling the fusion function simultaneously, listing themselves as the first parameter and the other as the second, effectively destroying one another.

That only took me several hours to figure out -_-

Any ideas for how I can get just one to call the function?

avatar image Kiwasi · Jun 20, 2014 at 12:21 AM 0
Share

In your fusion function check if both gameObjects exist. If one has already been destroyed then do nothing.

To add to this you could set the return type of your fusion function to bool, then return true if the fusion is successful and false if it fails.

I would also suggest not asking further questions on a answered thread. You will get more response by opening a new thread.

avatar image youngapprentice · Jun 20, 2014 at 02:50 PM 0
Share

Thank you!

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Grabbing a cube makes it expand and increase in size. 1 Answer

How can i destroy cubes that is randomly generated when i have passed them? 1 Answer

Something wrong with destroying script 0 Answers

Explosion before destroying 2 Answers

Destroy Object on Mouse Click 5 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