UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Ui Module / QR Generator Completed

Ui Module — UGTK

QR Generator

Summary

Generates a QR code into a RawImage from a URL built at runtime. Mn_QrLinkBuilder assembles the final URL from configurable (fixed or random) query parameters; Mn_QrFlowBase resolves the URL, renders the QR (local ZXing, remote PNG, or remote SVG) and can export it as PNG. Mn_QrFlowDirect uses the long URL as-is, while Mn_QrFlowShortLink first turns it into a PHP short link.


Content


Modules Dependencies

Only in the demo scene. The Debug scene of this module also uses Minigames/TrisSystem. Nothing in the runtime code needs it: import this module on its own and it works, but the demo scene opens with a missing script where that component was.


Setup

Two flows ship, and the choice between them is about how long the encoded text is.

Mn_QrFlowDirect (prefab DirectQrCode) encodes the URL itself. Simple, works with no server - but a QR grows denser as the text grows, and a long URL with several parameters produces a code that a phone camera struggles to read at the size it is actually printed or shown.

Mn_QrFlowShortLink (prefab LittleQRCode) sends the URL to your backend, gets a short id back and encodes that. Mn_PhpCreateShortLink and Mn_PhpResolveShortLink are the two Mn_PhpOperationBase halves; both need an endpoint before the flow works at all.

To build the address, use Mn_QrLinkBuilder with Mn_QrSerializedLinkInput for the parameters, and ParamValueMode to decide whether a value is fixed in the inspector or read at runtime. QrRendererMode selects how the code is drawn.

Two of the three renderer modes are opt-in and off by default. QrRendererMode offers:

Mode Needs Off by default?
RemotePng the qrserver API, so a network round trip no, this is what works out of the box
LocalZXing the UGTK_ZXING scripting define yes
RemoteSvg the UGTK_VECTORGRAPHICS define, plus Unity's Vector Graphics package yes

Neither define is set anywhere in the package. Selecting one of those two modes without adding the matching define to your project settings compiles fine and generates nothing - so if you want the local, network-free, sharpest option, adding UGTK_ZXING is the step that is easy to miss.

Plugins/WebGL/UGTK_DownloadBridge.jslib is what lets a WebGL build hand the generated image to the user as a download, since a browser page cannot write a file itself.

Test the code at the size it will really be used, on a phone, not zoomed in on a monitor. That is the only measurement that decides whether direct encoding is enough or the short-link flow is required.


How To Use


Testing Scene

Open QrCodeScene in the module's Debug/ folder.

What to do, in order:

  1. Generate a code from a short string and scan it with a phone.
  2. Generate one from a very long URL and scan that.
  3. Shrink the image on screen and scan again.
  4. Generate from an empty string.

Steps 2 and 3 are the pair that matters: more data means a denser code, and a dense code needs more pixels to stay scannable. A QR that reads perfectly on your monitor can be unreadable on a phone screen or a printed flyer, and the only way to know is to point a camera at it.

QrCodeScene: the two placeholders are empty until Generate is pressed, then both codes appear and Download becomes available. This is RemotePng, the default mode, so the images come from the qrserver API — with no network the placeholders stay empty and nothing says why.


Technical Info


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 5 modules in total.