- Home /
Collider callback after disabling
Disabling 2d trigger collider in editor results in firing OnTriggerExit2d callback. However, disabling the same collider in code collider.enabled = false;
does not fire the callback.
To me this look like a bug. If not, how to disable collider in code so that it will fire the callback?
Did more testing. It turns out that the problem is not scripting related. It is a bit hard to explain the case that I am dealing with properly, so here is the image:
The Green thing moves onto the Blue thing standing on the White thing, and kills the Blue thing. Blue disables its collider. Then White should register Blue exit. But it does not register it. This is the log of White collisions and it is missing Blue exit, which should be result of Blue collider disabling. 1 Blue enter 2 Green enter 3 Green exit
Now, if Blue is being killed without Green involved, its exit (by disabling collider) is being correctly registered by White. So, the bug only occurs if Blue is being killed while also colliding with Green. And the same bug occurs if ins$$anonymous$$d of Blue there is the second Green.
Answer by bennett_apps · Aug 02, 2018 at 07:34 PM
You'll just have to call the same lines in your OnTriggerExit2D callback...again. I guess unity didn't think of that...it's kinda a special case.
The problem is that the OnTriggerExit2D should be automatically called in other behaviour, not in the one where the collider is being disabled.
Are you saying that OnTriggerExit2D isn't working EVER? If so, pls post your code so i can check it for problems.
I did more testing, and it works in other scripts, but doesn't work in this particular one. The code is quite straightforward. In the inspector assigning the collider as one of the elements of the toDisable
array, and then disabling all of the behaiour: foreach (var behaviour in toDisable) behaviour.enabled = false;
Your answer
Follow this Question
Related Questions
Raycast2D hits itslf 2 Answers
Physics2D.Raycast.collider is always returning an object? 4 Answers
Transform.translate bullets problem 0 Answers
Custom 2D physics of a rope (top-down view) 1 Answer
Animate projectile before throwing? 1 Answer