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 youdonotexist · Nov 05, 2011 at 10:35 PM · destroyunitysteer

Correct way to destroy GameObject with UnitySteer Steering attached

What is the best way to destroy a GameObject with a Steering script attached to it?

For example, I have many Vehicles traveling along a path. When a Vehicle reaches the last node, OnArrive is called. OnArrive destroys the Game Object.

On Destroying, I get the following error:

 MissingReferenceException: The object of type 'NPCVehicle' 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.
 DetectableObject.get_Position () (at Assets/_Library/UnitySteer/Behaviors/DetectableObject.cs:58)
 Vehicle.PredictNearestApproachTime (.Vehicle other) (at Assets/_Library/UnitySteer/Behaviors/Vehicle.cs:545)
 SteerForNeighborAvoidance.CalculateForce () (at Assets/_Library/UnitySteer/Behaviors/SteerForNeighborAvoidance.cs:104)
 Steering.get_Force () (at Assets/_Library/UnitySteer/Behaviors/Steering.cs:40)
 Steering.get_WeighedForce () (at Assets/_Library/UnitySteer/Behaviors/Steering.cs:82)
 AutonomousVehicle.FixedUpdate () (at Assets/_Library/UnitySteer/Behaviors/AutonomousVehicle.cs:84)

I've subclassed AutonomousVehicle, but it's not overriding any of the AutonomousVehicle or Vehicle methods.

I've attempted to do Destroy(o), Destroy(o, waitTime), and DestroyImmediate(o) on the gameObject.

[edited for grammar]

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

Answer by Bunny83 · Nov 06, 2011 at 02:41 AM

It doesn't seem to be a problem with the object itself. It seems that another object (or manager) still holds a reference to the object and accesses it's position without a null-check. I never worked with UnitySteer but from your stacktrace and the current source code (i've just downloaded) it seems that another nearby vehicle is referencing your vehicle via their "Radar"-system which actually uses Physics.OverlapSphere to get the neighbors for collision avoidance.

Usually Destroy is always delayed until the end of frame so such errors won't happen. Make sure you never ever use DestroyImmediate to destroy gameobjects or components at runtime. It's a function basically designed for use in the editor (or in some very rare cases at runtime).

If the problem persists, try to disable it first and then use Destroy with a small delay. It seems the neighbor-detection ignores deactivated objects.

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 youdonotexist · Nov 06, 2011 at 02:59 AM 0
Share

Turns out you were exactly right about the Radar. The UnitySteer Radar has a field "Detect Disabled Vehicles". Setting this to false fixed all the $$anonymous$$issingReferenceExceptions.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

i need a script to make object be destoryed after touching another 1 Answer

Destroy(this) not working properly 2 Answers

Destroying object without interrupting audio source? 2 Answers

Making projectiles disappear when they hit the ground 2 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