UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Component Module / Ping Pong Movement Component Completed

Component Module — UGTK

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

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:

Good to know:


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:

  1. Press play and watch at least two full round trips. One is not enough — see below.
  2. Select 3DFollowComponentA and 3DFollowComponentB in the hierarchy and watch them switch on and off in turn as the state machine changes state.
  3. 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

Real dependenciesOpen in the map →

Depends on 5

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.