UGTK / Toolkit / Utility Systems / Collision System Completed
Collision System
Summary
The Collision System brings Unity's collision, trigger and pointer callbacks into the inspector. Instead
of writing a script with OnTriggerEnter for every object that has to react, you drop a component and
wire the reaction as a UnityEvent — the same way you wire a Button.
It covers three families: 3D physics, 2D physics, and pointer interaction (mouse or touch) on an object.
Content
Modules Dependencies
None. Four independent components that only use UnityEngine and UnityEngine.EventSystems.
Setup
3D physics — drop the collider prefab that matches the shape you need:
2D physics — the 2DColliderObject prefab:
Pointer interaction — ColliderMouse for the cursor, ColliderTouch for the finger:
Then wire the reactions in the inspector, like any UnityEvent:
How To Use
Mn_Collider3DEvents / Mn_Collider2DEvents expose the six physics callbacks:
| Event | Raised |
|---|---|
onCollisionEnter / onCollisionEnter2D |
when the collision begins, with the collision data |
onCollisionStay / onCollisionStay2D |
every physics step while it lasts |
onCollisionExit / onCollisionExit2D |
when it ends |
onTriggerEnter / onTriggerEnter2D |
when something enters the trigger, with the other collider |
onTriggerStay / onTriggerStay2D |
every physics step while it is inside |
onTriggerExit / onTriggerExit2D |
when it leaves |
SetInteraction(false) silences the whole set without touching the collider: physics keeps behaving
identically — the object still blocks, still pushes — only the reactions stop. That is the difference from
disabling the collider, and it is usually what you want during a cutscene or a death animation.
Mn_ColliderMouse / Mn_ColliderTouch expose enter, over, exit, down, up and hold. The Hold event
is the one Unity does not give you: it fires every frame while the press lasts, which is what a
charge-up or a long-press needs.
Good to know:
Stayevents fire every physics step, up to 50 times a second per contact. Anything heavier than a flag flip belongs inEnter.onMouseUp/onTouchUpfire on release anywhere, not only over the object: the press started here, so this component gets the release. For "released on the object", check the pointer is still inside.- The two pointer components are near-identical: on a touch device the EventSystem reports touches
through the same pointer callbacks, so
ColliderMousealso responds to a finger. UseColliderTouchfor intent, not because the other one would not work.
What Unity Requires Anyway
This module wires the callbacks, it does not remove Unity's own requirements. Almost every "it does not fire" comes from one of these:
- Physics events need a Rigidbody. Two static colliders never generate any callback: at least one of
the two objects needs a
Rigidbody(orRigidbody2D), even a kinematic one. - Trigger events need
Is Triggeron one of the colliders — and a trigger does not raise collision events, only trigger ones. - The layers must collide in the Physics collision matrix.
- Pointer events need an
EventSystemin the scene and a raycaster that can see the object: aGraphic Raycasteron the canvas for UI, aPhysics Raycaster(orPhysics 2D Raycaster) on the camera for colliders. Without the raycaster nothing is raised and nothing warns you. - 2D and 3D do not mix: a
Collider2Dnever talks to aCollider, and the two components are not interchangeable.
Testing Scene
Open Debug/CollisionScene.unity and press Play: the objects collide and CollisionCallbackExample logs
every event it receives, so you can see which ones actually fire.
Technical Info
| Path | Content |
|---|---|
Scripts/Mn_Collider3DEvents.cs |
The six 3D physics events plus SetInteraction |
Scripts/2DCollision/Mn_Collider2DEvents.cs |
The six 2D physics events plus SetInteraction |
Scripts/2DCollision/Mn_ColliderMouse.cs |
Mouse enter/over/exit/down/up/hold through the EventSystem |
Scripts/2DCollision/Mn_ColliderTouch.cs |
The same for touch |
Prefabs/3DColliders/*.prefab |
Box, Sphere and Capsule ready to use |
Prefabs/2D/*.prefab |
2D collider, mouse and touch |
Debug/CollisionCallbackExample.cs, Debug/CollisionScene.unity |
Sample listener and test scene |
© 2026 Marcello De Bonis. All rights reserved
Depends on 0
- Standalone: no other module required.
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 0 modules in total.
UGTKengine within an engine


