UGTK / Toolkit / Ui Module / QR Generator Completed
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
UGTK.UIModule.RawImagePreserveAspect— target image supports aspect-preserving QR display.UGTK.Api.PhpConnectionSystem— short-link creation/resolution against the PHP backend.UGTK.UtilitySystems.CopyPasteSystem—[CopyPaste]/[ReadOnlyInInspector]attributes on the final URL field.- Optional scripting defines:
UGTK_ZXING(local ZXing renderer) andUGTK_VECTORGRAPHICS(Unity Vector Graphics for the SVG renderer). Without them the flow falls back to the remote PNG API.
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
- Add either
Mn_QrFlowDirect(long URL) orMn_QrFlowShortLink(PHP short link) and assign aMn_QrLinkBuilder, the targetRawImage, and thebaseUrl. - On the link builder, declare parameters with a
UseEditorValueorRandomOnGeneratemode; each param exposes anonValue(string)event fired at generation time. - Call
Generate()to build the URL, resolve it (withresolveTimeoutSeconds), and render the QR atqrSize(auto-upscaled to the RawImage size).onFinalUrlGenerated/onBaseUrlGeneratedfire on success. - Choose the renderer via
rendererMode(LocalZXing,RemotePng,RemoteSvg); missing defines fall back toRemotePng. - Runtime helpers:
AddOrUpdateParam(key,value),ChangeBaseUrl(url),SetDefaultPngFileName(name), andDownloadCurrentQrAsPng()(WebGL download bridge, Android gallery, or Windows Explorer reveal depending on platform).
Testing Scene
Open QrCodeScene in the module's Debug/ folder.
What to do, in order:
- Generate a code from a short string and scan it with a phone.
- Generate one from a very long URL and scan that.
- Shrink the image on screen and scan again.
- 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
- Mn_QrFlowBase: Abstract flow — resolves the final URL, runs the QR render pipeline, applies the texture to the RawImage and handles PNG export per platform.
- Mn_QrFlowDirect: Resolves
finalUrl = longUrlwith no backend call. - Mn_QrFlowShortLink: Resolves the final URL by creating a PHP short link via
Mn_PhpCreateShortLink. - Mn_QrLinkBuilder: Builds the URL from serialized parameters (fixed/random), supports an override URL and fires per-parameter value events.
- Mn_PhpCreateShortLink / Mn_PhpResolveShortLink: PHP endpoints for creating and resolving short links.
- ParamValueMode / QrRendererMode: Enums for parameter value source and QR renderer selection.
© 2026 Marcello De Bonis. All rights reserved
Used by 2
Measured from the repository: code references (asmdef) plus prefab and asset GUIDs. Importing this module alone brings in 5 modules in total.
UGTKengine within an engine


