as probably some of you know, these two methods are broken.
OnTriggerEnter2D is called every single frame, instead of the first one, while OnTriggerExit2D is never called.
Some of you has a solution? some idea to solve this, or maybe way to fix it that i don’t know?
ps: Some people think that the problem is the animator, but i disabled it and the problem is still there
pps: Don’t answer something like “You have to use collider2D instead of collider”, i know that^^
Hm… while there definitely is a bug with OnTriggerEnter2D being called more than once, OnTriggerExit2D works fine for me.
My workaround for OnTriggerEnter2D is to keep a list of the GameObjects that have already been triggered until they exit.
This exact same thing happened to me. I just create a “canenter” boolean which upon the first entry gets shut off so subsequent entries can be ignored. Once you get an exit it gets turned back on again.
Exit is a bit hairier. One thing I’ve done is ignore OnTriggerExit2D completely (because it never seems to work consistently for me) and instead create a boolean variable “hasexited” or whatever and in LateUpdate set it to true while OnTriggerStay (which I believe will always execute before Update) sets it to false again, thus as far as Update is concerned things should be accurate. I think. It seems to work, anyway, but it’s very hacky and I’d recommend finding a better solution…
negative_zero i thougth the same thing, and i thik now i’m gonna implement it, but thats absurd -.-
now the question is:
having all these trigger methods being called every frame, is, in terms of performances, better then having old good 3d colliders?
You set their Z value to an high number, so that they act exactly like 2d colliders, and maybe, at this point, they are better
nope, i’m using an empty object with a circe collider. The empty object has an animator that animates all of his children.
I thought that the animator was the problem, especially because i knew for certain that it worked since a few days ago…but removing it changes nothing