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
1
Question by Redspot · Mar 15, 2011 at 01:06 PM · objectaccessmissingreferenceexceptiondestroyed

Trying to access destroyed object

Ok, I am new to coding so have patience! Im making my first simple project, where the player (a cube) is moving constantly forward, collides with things (spheres and cylinders) on a straight road and collect points on collision. The sphere and cylinder creates a particle effect on collission and then disappears.

I have created prefabs of the cylinder, placed copies of them onto the road (all works fine). I created a sphere, created a prefab of it, and added the same code as the cylinders have! But now "only" the first sphere prefab works...

The following weird thing happens! Also the following sphere prefabs works AS LONG AS THEY ARE REALLY CLOSE, and gets a collission within aproximately 1 second AFTER collission with first sphere.

If I increase the distance between the spheres on the road (so time between collisions are more than 1 sec), I get an error message:

MissingReferenceException: The object of type ParticleEmitter has been destroyed but you are still trying to access it. Your script should either check if it si null or you should destrouy the object.

related to this another thing happens... if I skip to collide with the first sphere and only collides the last ones (that I have copy - pasted into the scene withing UNITY3D editor), the last ones will give the error immediately (at first collision forward), even if all collisions happened within a second (so here the 1 sec rule doesnt seem to happen).

Every cylinder and sphere have: Collider - Is Trigger activated.

here is the code attached onto spheres and cylinders:

// spelaren = player (cube)

var Partikelexplosion : ParticleEmitter; function OnTriggerEnter (myTrigger : Collider) { if(myTrigger.gameObject.name == "spelaren") { Instantiate(Partikelexplosion, transform.position, transform.rotation); Destroy(gameObject); } }

This code works WELL on the cylinders, no matter how far away from each other they are. Can anybody help me, and explain clearly for a beginner plz.

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
1
Best Answer

Answer by Ashkan_gc · Mar 15, 2011 at 01:24 PM

the particle emmiter object that you attached to your spheres might not be a prefab and is an object in your scene which will be destroyed after showing the effect. it might be the answer because it's not clear to me why the last sphere could not be collided even at the first time. i suggest that you do all you did again. 1 create an sphere and add the script to it. 2 make a prefab from it. 3 add the emmiter object to the prefabs explosion property in your script. 4 place instances of the prefab in your scene. the code is fine. however using the Plaer tag instead of the player object's name is faster. set the tag of the cube to player and try to check it's tag in Trigger events instead of the gameObject's name.

Comment
Add comment · Show 2 · 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 Redspot · Mar 15, 2011 at 04:23 PM 0
Share

THX many times Ashkan! The particle to the spheres were not PREFABS! I changed that, and made all speheres from 0, as u described, and now they work fine! Im real happy now thanks to u! :-)

avatar image Ashkan_gc · Mar 15, 2011 at 07:16 PM 0
Share

actually unity answers is here to make us happy! nothing special boy! it's happy cause you are happy.

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

No one has followed this question yet.

Related Questions

Destroyed Object Error 2 Answers

MissingMethodException error while trying to play animation when GameObject is destroyed 0 Answers

Access object from script problem. 1 Answer

Howto access a variable in another script? 1 Answer

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 . 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