Sorry, i saw a few threads with my problem, but there are no solution. So…
I have player. Player beats enemies (colliders) by sword. Sword is simple sprite with collider(trigger). When i enable gameObject “Sword” it calls onTriggerEnter2D and enemy “under” Sword get damage. Then i disable my Sword and eneble in some “attackTime”. And it works, but only if my character or enemies move. And it doesn’t if they all are still.
I tryed to disable Collider Component after each attack and eneble it before next. Result is the same.
And i noticed that problem exists only if one out of pair is real collider, not trigger. If both objects are trigger all works well.
I dont think you fully understand Kurt’s response. If you cannot enable all the triggers at all times (for whatever reason), you should track them. Throw in a Debug.Log() statement in each OnTriggerEnter2D, Stay2D, Exit2D and see if those are getting called when they should be.
With the Debug.Logs in place, you need to test every scenario. Have the player and object standing still, both moving, one moving, etc. Start disabling/enabling colliders in each scenario and see what is happening. The debug.logs will really help you. Use them everywhere to see what is going on.
That’s not the point at all. I ALREADY know how it works. I described it above and it’s not what I need. When enabled again, the trigger fires only if one of the objects has changed position.
Kurt gave me the option of not turning off the trigger at all. This is an acceptable option, but it will greatly complicate my code. I’ll have to replace the trigger runner with a triggerStay, and give my weapon damage a timer inside the triggerStay, and toggle my weapon sprite on/off (simulating disabling all weapons). And that’s okay, but this system is completely inappropriate when I have a different type of weapon that I can’t keep on all the time.
I solved my problem by not turning the sword on and off, but creating and destroying it. That. the weapon triggerEnter is new each time. It works. Yes, it may be wrong in terms of performance, but in my project the issue of lack of resources is not worth it.
I wrote all the 2D physics code for Unity and I don’t understand what you’re seeing here. When you disable a physics collider, all its underlying physics details are destroyed. When you enable it, they are recreated. During the next simulation step, all contacts for it will be calculated and reported. It won’t need to “move”. If you disable a collider, it has no state so when it’s enabled and there’s a contact, it’ll report triggerenter/collisionenter.
Your description isn’t actionable as it’s pretty vague TBH. If you have a simple reproduction project of the problem then I would suggest hosting it so I can take a look. Alternately, DM me on these forums with your email and I’ll set-up a private workspace for you to do that.
I have to apologize. I’ve try to repeat this situation with re-enebling Trigger instead Instantiate - and some miracle happend: now all works as you say. Of course there was some mistace in my code or work’s logic. (But i still don’t know where exactly i made a mistake)