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 Ekta-Mehta-D · Feb 27, 2013 at 11:23 AM · destroyexplosionmissingreferenceexception

missing object woe beginner

MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

Here, I want to make explosion but it throws such exception Before destroying object.

here is my code:

 var shotSound: AudioClip; // drag a shot sound here, if any
 
 // the PickupController component of the 'PickupSpawnPoints' GameObject
 private var pickupController:PickupController;
 public var explosion : Transform;
 function Update(){
   if (Input.GetKey(KeyCode.Space)) {
 
       Shoot();
       }
 } 
 
 function Shoot(){
     if (shotSound) audio.PlayOneShot(shotSound); // play the shot sound
        var hit: RaycastHit;
     
     var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     
     if (Physics.Raycast (ray ,hit ,200))
     {
         Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
         var pickupSpawnPoints:GameObject = hit.collider.gameObject;
         var clone : Transform;
       
         if(pickupSpawnPoints.tag == "Pickup")
         {
                clone = Instantiate(explosion,pickupSpawnPoints.transform.position, transform.rotation);
             Destroy(clone.gameObject);
         }
     }       
 }

I am currently learning unity. Please help me to solve this error . Thanx for ur help in advance,..

Comment
Add comment · Show 12
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 Fattie · Feb 27, 2013 at 11:31 AM 0
Share

please use CLEAR SHORT question titles

avatar image Mikilo · Feb 27, 2013 at 11:34 AM 0
Share

Hi, did you checked if explosion was not null?

avatar image Ekta-Mehta-D · Feb 27, 2013 at 11:37 AM 0
Share

yes have checked. its not null

avatar image Mikilo · Feb 27, 2013 at 11:41 AM 0
Share

Can you give us the line? (In the code above, of course!)

avatar image Ekta-Mehta-D · Feb 27, 2013 at 11:44 AM 0
Share

clone = Instantiate(explosion,pickupSpawnPoints.transform.position, transform.rotation); // here i get error

Show more comments

1 Reply

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

Answer by AlucardJay · Feb 27, 2013 at 05:34 PM

You are destroying your object in the very same frame that you are instantiating it :

 if(pickupSpawnPoints.tag == "Pickup")
 {
     clone = Instantiate(explosion,pickupSpawnPoints.transform.position, transform.rotation);
     Destroy(clone.gameObject);
 }

If you want to instantiate your particle prefab, let it complete its emission, then destroy it, you have 2 options.

First, look at the Unity Scripting Reference for Destroy : http://docs.unity3d.com/Documentation/ScriptReference/Object.Destroy.html

Note you can put a delay right there in the command :

 // Kills the game object in 5 seconds after loading the object
 Destroy (gameObject, 5);

the second option is to attach a script to your particle prefab :

 #pragma strict
 
 public var destroyTime : float = 10.0;
 
 function Start() 
 {
     Destroy( gameObject, destroyTime );
 }

Pick one, and have fun !

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

12 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

Related Questions

Destroying and Loading Object Promblem? 1 Answer

A node in a childnode? 1 Answer

gun muzzle flashes 2 Answers

How do I destroy a specific clone of a GameObject? 1 Answer

Explosion Using Particle System 0 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