UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Ui Module / Char Limiter System Completed

Ui Module — UGTK

Char Limiter System

Summary

The Char Limiter System caps how many characters the player can type into a TMP_InputField and keeps a live count of the current length. One component, one number: it applies TMP's own characterLimit and trims anything that gets through anyway, so the field can never hold more than the maximum.


Content


Modules Dependencies

None on the UGTK side. It requires Unity's TextMeshPro package, since it drives a TMP_InputField.

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
UIModule/TextUpdaterSystem Mn_TextUpdater (in Char Limiter InputField (TMP))

Setup

Drop the Char Limiter InputField (TMP) prefab under a Canvas — a TMP input field with Mn_CharLimiter already on it:

Or add Mn_CharLimiter to an existing input field: the component is [RequireComponent(typeof(TMP_InputField))], so it has to live on the same GameObject as the field.


How To Use

Set Max Characters (default 20) in the inspector and you are done. On Awake the component writes that value into the field's characterLimit, subscribes to onValueChanged, and initialises Current Characters with the length of whatever the field already contains.

var limiter = inputField.GetComponent<Mn_CharLimiter>();

int used = limiter.currentCharacters;          // live count, updated on every keystroke
int left = limiter.maxCharacters - used;        // "23 / 30" style counters

Both fields are public, so a counter label can simply read currentCharacters in Update, or you can add your own listener on the input field's onValueChanged.

Good to know:


Testing Scene

Open Debug/CharLimiterScene.unity and press Play: type into the field and the input stops at the configured maximum:


Technical Info

Path Content
Scripts/Runtime/Mn_CharLimiter.cs The whole system: applies characterLimit, listens to onValueChanged, trims the overflow, updates the count, unsubscribes in OnDestroy
Prefabs/Char Limiter InputField (TMP).prefab TMP input field with the component already attached
Debug/CharLimiterScene.unity Test scene

Mn_CharLimiter fields: maxCharacters (int, default 20), currentCharacters (int, read it).


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 1

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 2 modules in total.