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 KnowHope · May 05, 2013 at 05:33 PM · collisionnetworkdestroyenter

Network.Destroy in OnCollisionEnter; not working.

I'm in the process of learning Unity's network features (so please excuse any horrendous code I paste), and I'm having trouble with a Network.Destroy inside an OnCollisionEnter.

Current function is as follows:

 function OnCollisionEnter(collision : Collision)
 {
     if (networkView.isMine && collision.collider.gameObject == target)
     {
         Network.Destroy(gameObject);
         Debug.Log("Destroyed");
     }
 }

The log won't even work, so I'm guessing it's to do with the if statement. This script is obviously attached to the object I want to destroy, while the 'target' (set through the inspector as a variable) is the other object. Both objects have rigidbodies and colliders, and neither are set as triggers. They are both also prefabs, if that makes any difference. Thanks for any help.

Comment
Add comment · Show 4
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 ExTheSea · May 05, 2013 at 05:37 PM 0
Share

First what is target?

Second you should do some Debug logging like this:

     function OnCollisionEnter(collision : Collision)
     {
       Debug.Log("CollisionEnter gets called");
       Debug.Log("Is NetworkView $$anonymous$$e? " + networkView.is$$anonymous$$ine);
       if(collision.collider.gameobject == target)
          Debug.Log("Collision GO is the same as target");
       else
          Debug.Log("Collision GO and target are different");
     if (networkView.is$$anonymous$$ine && collision.collider.gameObject == target)
     {
     Debug.Log("We nearly did it :)");
     Network.Destroy(gameObject);
     Debug.Log("Destroyed");
     }
     }

This way you can check where the problem may be.

avatar image KnowHope · May 05, 2013 at 05:54 PM 0
Share

Ok, so I added the debugging lines and it reaches the "Collision GO and target are different" line (networkView.is$$anonymous$$ine returned as true). Guessing it's to do with the collision comparison then?

'target' is a GameObject variable in the script, which is set in the inspector as a prefab bullet object; the object that this is supposed to collide with.

avatar image KnowHope · May 05, 2013 at 06:38 PM 0
Share

Ah, nice. It works. Thanks a lot!

avatar image ExTheSea · May 05, 2013 at 06:39 PM 0
Share

I converted my comment to an answer so that you can accept it to mark the question as solved.

1 Reply

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

Answer by ExTheSea · May 05, 2013 at 06:24 PM

The Prefab is not the same as the instance which is colliding with this gameobject. You should do your gameobject detection with tags. Just add a tag to the bullet like "Bullet" and then you can do:

 if (networkView.isMine && collision.collider.gameObject.tag == "Bullet")
Comment
Add comment · 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

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

13 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

Related Questions

Network.Destroy and collision; destroying correct object. 1 Answer

View ID AllocatedID: X not found during lookup. 1 Answer

[SIMPLE] Not loose speed when destroying colliding object 1 Answer

Destroy object after 5 collisions 1 Answer

Destroy On Collision 4 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