UGTK / Toolkit / Component Module / Ping Pong Movement Component Completed
PingPong Movement Component
Summary
The PingPong Movement Component makes an object travel back and forth between two points, forever: a
moving platform, a patrolling guard, a lift, a hazard sweeping across a corridor.
It is not a new behaviour but a composition: a Follow component moves the object, and a small state machine swaps the target between the two endpoints every time one is reached. Everything is already wired in the two shipped prefabs — there is no ping-pong script to add.
Content
Modules Dependencies
- Follow System: performs the actual movement towards each endpoint.
- StateMachine: holds the "going to A" / "going to B" states and flips between them.
- Pooling System: used by the prefabs to recycle the moving objects.
- Event System: carries the "endpoint reached" notification that drives the state change.
Carried inside the prefabs. These modules are not referenced by the assembly definition - the components are simply already attached to the prefabs this module ships. Remove one of them from the project and the prefab keeps its layout and loses that behaviour, with nothing in the console to say so.
| Module | Component, and the prefab carrying it |
|---|---|
UtilitySystems/ActivationSystem |
Mn_GameObjectActivation (in PingPong2DObject), Mn_GameObjectActivation (in PingPong3DObject) |
Setup
Drop PingPong2DObject or PingPong3DObject into the scene — pick the 3D one for objects in the
world, the 2D one for UI (see the note on spaces in the Follow System documentation):
Then assign the two endpoints and configure the follow settings — speed, curve, stop distance and tolerance all come from the Follow component.
How To Use
Everything is configured on the child Follow component; the ping-pong itself has no options of its own. The settings that matter for this use:
- Speed and Movement Curve — a linear curve gives a constant sweep (a conveyor), an ease-in-out curve gives the pendulum feel of a lift slowing down at each end.
- Curve Mode
Distancemakes each leg take the same time regardless of the gap between the two points: use it when several platforms must stay in sync. - Tolerance decides when an endpoint counts as reached, and therefore when the direction flips. Too small and the object jitters at the ends without turning around.
Good to know:
Mn_PingPongMovementComponentis an empty placeholder. Adding it to a GameObject does nothing at all; the behaviour lives in the prefabs. Use the prefabs.- The object that moves is the Follow component's
Owner, that is its parent — the same rule as the whole Component Module. - The endpoints are transforms in the scene, not offsets: moving the parent of the platform moves the endpoints too, which is usually what you want, but it means a prefab dropped in a new scene needs its endpoints assigned again.
Testing Scene
Open PingPongScene in Debug/. It holds PingPong3DObject between the two endpoint markers
(WallA, WallB) plus a Canvas. Press play: the object travels to one endpoint, turns round, and
comes back, indefinitely.
What to check, in order:
- Press play and watch at least two full round trips. One is not enough — see below.
- Select
3DFollowComponentAand3DFollowComponentBin the hierarchy and watch them switch on and off in turn as the state machine changes state. - Clear the target on one of the follow components and play again: the console warns that the follow is heading for (0,0,0).
Why two round trips and not one. Until 2026-08-03 this scene did not animate at all, and the reason
is worth knowing because it applies to any component driven by being switched on and off:
Mn_FollowComponent started following from Start(), and Unity runs Start once, the first time
an object becomes active. A ping-pong alternates two follow objects forever, so from the second
activation onwards nothing restarted the movement. Raising startFollowingOnStart on its own could
never have fixed it. The component now also restarts on OnEnable, guarded so the first activation is
still handled by Start and the original ordering is unchanged.
Technical Info
| Path | Content |
|---|---|
Prefabs/PingPong2DObject.prefab |
Ready-made composition for UI space |
Prefabs/PingPong3DObject.prefab |
Ready-made composition for world space |
Scripts/Mn_PingPongMovementComponent.cs |
Empty placeholder kept for backwards compatibility: no logic |
Debug/PingPongScene.unity |
Test scene |
© 2026 Marcello De Bonis. All rights reserved
Used by 0
- No other module depends on it.
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 13 modules in total.
UGTKengine within an engine


