[SOLVED] Small trigger bug


I’ve run into a small issue while making my game for playhack.

I’m trying to turn off a trigger (the entity, not the component) and then move it later, but when I activate it again it checks collisions on the original position for the first frame.

I worked around it by detaching the “triggerenter” event, turning off the entity, moving it, turning it on, and then reattaching the event inside a setTimeOut 1. Which is really annoying.

Is there any other way to fix it?

Thanks for reading.

Seems like a bug here.

Do you have a simple project for replication?
So we can log a Issue in engine repository (it is related to engine): https://github.com/playcanvas/engine/issues

Here I recreated it: https://playcanvas.com/project/380310/overview/trigger-bug
Press space to try to reset the ball. there is a work arround on the “fireOnSpace” script

Here is how it works:
A trigger moves into a rigidbody and gets deactivated on the “triggerenter” event.
Another entity resets the trigger’s position, when the player presses Space, and then activates it.
The trigger checks for collision right where it got deactivated, so it just gets deactivated again.

This only happens if I reset the trigger on an “update” function. It will work as intended if I activate it on an event or inside a “SetTimeOut”, even if the delay is 0.

I hope you can understand me, my english is not perfect.

1 Like

Thank you for example, that helped a lot to replicate and fix issue.
So looking in engine sources we do syncEntityToBody, which brings trigger body to entity position (not sure why it is called vice-versa). That method is called before script update loop if entity and trigger is enabled. Means that trigger wont be synced till next update tick of components updates, which happens after physics simulation. So for one tick you will have trigger in old location.

I’ve added extra sync to enable method on trigger, to make sure that it synced after being enabled during script update.
That resolves the problem.

We will deploy the engine shortly.
By now you can add this line to your code that resolves the issue:


We should be deploying engine today or early next week. We usually deploy it very often :slight_smile:

1 Like

Thanks for fixing it!
I’m glad I could help.

1 Like

This kind of help - is very useful, and wish more people could contribute in such way.

1 Like