Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NearSensor and its dependent behaviors try to access rigidbodies that have been destroyed at runtime #5

Open
SpaceToastCoastToCoast opened this issue Sep 19, 2016 · 0 comments

Comments

@SpaceToastCoastToCoast
Copy link

Great library! I've adapted it to a 3d project with movement along the x and z axes and it's working beautifully--but there's a major oversight when it comes to rigidbodies that have been destroyed after being added to the NearSensor's hashset.

I tried implementing a solution within the NearSensor script to first check if the rigidbody exists and is enabled before adding to the hashset--but that didn't address the case in which rigidbodies are destroyed after being added (such as when an enemy is killed). Cohesion, Separation, VelocityMatch and CollisionAvoidance were still trying to access the destroyed rigidbody, throwing null exceptions every frame.

I would suggest, in NearSensor-dependent scripts, at the beginning of the foreach loop iterating over members of the rigidbody hashset, to make it first check if the rigidbody at this index is null before accessing it. When I added this check, there were no more errors.

(P.S. I'd be happy to submit a pull request if you'd like to see the various tweaks I made to add this library to my project!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant