Skip to main content

BoxCollider2D not working not registering clicks when adding the collider component during runtime.

During runtime, the BoxCollider2D component does not appear to work, even if this component was added by using .AddComponent<BoxCollider2D>(); in the code

This could be caused by a known issues in the Unity Playworks Plugin engine.

images-medium

Possible solution:

  • Disable and enable the box collider in single frame when the object is activated. This can be in Awake() or Start(). For example:
void Awake()
{
_collider = gameObject.AddComponent<BoxCollider2D>();
_collider.enabled = false;
_collider.enabled = true;
}