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 XMatrix2X · Nov 14, 2013 at 02:43 PM · crashexplosiondetonator

Unity Freezing On Successful Detonator Explosion

For some reason, when this script works as intended (Makes "Detonator" explode from the explosion framework plugin on contact with another object), Unity freezes. This is the script I used:

 function OnTriggerEnter (other : Collider) {
         gameObject.GetComponent("Detonator").Explode();
         yield WaitForSeconds(2);
         Destroy(this.gameObject);
     } 

The object that I have this script attached to does not have a detonator on it at all, but it still makes the explosion beforeit freezes. Removing the "gameObject.GetComponent("Detonator").Explode();" from the script fixes it, but I need the explosion to happen.

Comment
Add comment · Show 5
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 mattssonon · Nov 14, 2013 at 02:45 PM 0
Share

Do you need the object that has the code above to explode, or do you want the colliding object to explode?

avatar image XMatrix2X · Nov 14, 2013 at 02:52 PM 0
Share

I want the explosion to emit from the object that has this script (It is a missile).

avatar image mattssonon · Nov 14, 2013 at 03:03 PM 0
Share

Then why doesn't it have the Detonator script? It seems like that's the script making an object explode.

avatar image XMatrix2X · Nov 14, 2013 at 03:08 PM 0
Share

Having a detonator or not seems to have no effect on what happens. I think that when I call the component "Detonator", it pulls "Explode" from the script in my assets, not the detonator on it.

avatar image gajdot · Nov 14, 2013 at 03:17 PM 0
Share

If your detonator script is derived from monobehavior than it's highly unlikable. Did you try my answer?

2 Replies

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

Answer by XMatrix2X · Nov 15, 2013 at 12:26 AM

I don't know why but having the original script and disabling the detonators (Checkboxes next to their name in the inspector)causes it to work flawlessly. Thank you for helping!

Comment
Add comment · Show 1 · 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 · Nov 15, 2013 at 12:48 AM 0
Share

Choose your own answer as the correct one. :)

avatar image
0

Answer by gajdot · Nov 14, 2013 at 03:03 PM

You need to check first if you have a detonator, and only if it does do the rest of the code. something like:

 Detonator detonator = gameObject.GetComponent("Detonator");
 if(detonator!=null){
   detonator.Explode();
   yield WaitForSeconds(2);
   Destroy(this.gameObject);
 }

The problem is that you get a null expection when you try to use a function for a null object.

Comment
Add comment · Show 8 · 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 XMatrix2X · Nov 14, 2013 at 03:30 PM 0
Share

I had to change the script a little bit. It looks like this now:

 function OnTriggerEnter (other : Collider) {
 Detonator ;detonator = gameObject.GetComponent("Detonator");
 if(detonator!=null){
   detonator.Explode();
   yield WaitForSeconds(2);
   Destroy(this.gameObject);
 }
 }

It demanded that I add a semicolon after the first Detonator and that I insert another bracket at the bottom (For the OnTriggerEnter part). Now it's saying "(2,1): $$anonymous$$ identifier: 'Detonator" despite me now having a detonator script on the object.

avatar image gajdot · Nov 14, 2013 at 03:34 PM 0
Share

You probably had a variable called detonator already, do it like this:

function OnTriggerEnter (other : Collider) { Detonator localDetonator = gameObject.GetComponent("Detonator"); if(localDetonator !=null){ detonator.Explode(); yield WaitForSeconds(2); Destroy(this.gameObject); } }

avatar image XMatrix2X · Nov 14, 2013 at 03:40 PM 0
Share

I arranged it like this:

      function OnTriggerEnter (other : Collider) { 
         Detonator localDetonator = gameObject.GetComponent("Detonator"); 
         if(localDetonator !=null){ detonator.Explode(); 
         yield WaitForSeconds(2); 
 Destroy(this.gameObject); 
         } 
         }

I got the same error as before, "(2,1): BCE0005: $$anonymous$$ identifier: 'Detonator'."

avatar image XMatrix2X · Nov 14, 2013 at 03:51 PM 0
Share

In addition, having this script saved causes compiler errors across all of my scripts.

avatar image gajdot · Nov 14, 2013 at 07:43 PM 0
Share

This is really strange... With this information I can't help you, I would need to see the whole script to see the problem.

Show more comments

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

18 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

Related Questions

Explosion Elimination script 2 Answers

Detonator Explosion Framework Black squares around fireball 1 Answer

Unity Explosion Framework didn't work 0 Answers

Making detonator explosions follow the gameobject 2 Answers

Tank Missle Colide then explode and destroy 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