Destroyed trigger collision cause ammo errors

Yesterday I’ve run into an issue I’ve never had in PlayCanvas before.
In my current project I am having the issue, that after destroying entities that have my “Aura” template added as child which carries a Collision component as trigger area, these areas seem to “not be removed” in some sense.

No matter where the Tower entity carrying the aura is placed, after it’s destroyed, as soon as any entity with a rigidbody component gets near the origin of the scene (and into the radius of my aura size) it causes a sudden huge dump of errors from the ammo.wasm.wasm script.

I have debugged this to the very line inside the ammo.wasm.wasm where the error happens, I’ve tried removing various potential “leftover data” from the aura, but nothing helps.

And the worst of it all - it only happens when those auras are destroyed, but not with every tower that has auras.
I’ve tried seemingly everything, but I can’t find the difference that makes the one case cause the error and the other not.

I really love the simplicity of using collisions as aura triggers - and I would hate having to go back to looping through all alive enemies and checking for each one if they are in range.

Is there anybody with knowledge about this issue who could tell me why this is happening or how I can prevent it?
I would just ignore it, since the game is still working, if it just wouldn’t create such huge lag…

To reproduce the error:

  1. Select “build” in the bottom left corner
  2. Select E and 1 in the top right menu (my cheat menu for testing :smiley: )
  3. While holding the shift key, place at least one of these E1 Towers, and five towers in total (so for simplicity just place five E1)
  4. Click on one of the towers and click the “Select” button at the bottom, so that there is at least one E1 Tower you didn’t select.
    Depending on if you placed the towers near the middle the errors should pop up right away.
    If you didn’t, then they’ll appear as soon as enemies reach the middle.

Unfortunately, it’s quite a large project so it’s really difficult to help with.

Are you able to create a smaller demo project or at least narrow down where in the code people should be looking at to help with?

Right, the project is a bit large to have a quick look.

Some quick observations:

  • The error indicates that you are failing to access some object in Ammo (it was either already destroyed or you are using an invalid reference).
  • The amount of triggers and kinematic bodies before you press Select and after does not match. You probably want to debug your logic there.

Edit:
Try to make a blank project and emulate the issue. Like, alright, I imagine this box is my tower, and I made 5 of them. Then on mouse click I pretend I pressed Select UI button and I do this with them that is causing an error. Do you still get the error? If not, start adding stuff, that is similar to your original logic, like store them in array or however you are storing them, then destroy from there. If still no error, keep adding your logic bit by bit, until you have exactly same setup. At some point you will encounter the error and you will know what is causing it.

1 Like

That is a very smart idea and I feel kinda dumb for not thinking about it :smiley:
Thank you, I will try to isolate the problem and update you here.

What I can not explain is, how or why there is a trigger for the Entity “cube_Plane”.
That is our ground box.
It has a collision, but nowhere in the code the we ever set up a trigger for it…

Internally, the engine will parse the entity components one by one. When it parses the collision component first, it won’t see that there is a rigidbody component yet, so it will create a trigger first. It would then process rigidbody component and remove the trigger right after.

Not the most optimal logic, but it is what it is currently. This should not be an issue, as it is how all other projects work at the moment. The trigger gets created and destroyed at the same frame. If you are seeing a trigger that should be a rigidbody somewhere, it means you are reading a log that was shown right after the engine has created a trigger for it, but before it turned it into a rigidbody.

1 Like

Okay - So I couldn’t find the specific issue that is going on here.
Sadly couldn’t recreate it in a separat Project.
I “found” a workaround, by attacking an extra entity to the Aura template and giving that one the collision.
I they gave it a local position of Y = -100.
Then I just translate the template by Y + 100 on creation.
Since somehow the Aura seems to stay in the scene (even though I can’t find it anywhere while debugging) it at least gets put down to y = -100 and therefore no triggerevents cause the ammo error.

Ugly solution, but I’ll live with it, since I couldn’t find another solution in the last like 16 hours of searching and trying different aproaches.