UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Utility Systems / Interface Founder Completed

Utility Systems — UGTK

Interface Founder

Summary

The Interface Founder is a one-method utility: InterfaceFinder.FindAllInterfaces<T>() returns every MonoBehaviour in the loaded scenes that implements the interface T — including the ones on inactive GameObjects. It is what lets a manager talk to "everything that can be paused", "every saveable object" and so on, without keeping a registry by hand.


Content


Modules Dependencies

None. A single static class with no UGTK reference and no dependency beyond UnityEngine.


Setup

Nothing to set up: there is no component, no prefab and no scene. Add UGTK.UtilitySystems.InterfaceFounder to your assembly definition references and using UGTK.UtilitySystems.InterfaceFounder; to your script.


How To Use

using UGTK.UtilitySystems.InterfaceFounder;

// every MonoBehaviour in the loaded scenes that implements IPausable — inactive ones included
List<IPausable> pausables = InterfaceFinder.FindAllInterfaces<IPausable>();

foreach (IPausable p in pausables)
    p.Pause();

That is the whole API. The generic parameter is constrained to class, so it also accepts a base class — but the intent is interfaces, which GetComponent-style lookups handle poorly.

What it does and does not see

It finds It does not find
Components on active GameObjects Objects that live only in an unloaded scene
Components on inactive GameObjects Prefab assets that are not instantiated
Components across all loaded scenes (additive included) Plain C# classes: only MonoBehaviour is scanned
ScriptableObject assets

Cost. It is a full scene scan (FindObjectsOfType<MonoBehaviour>(true)): O(number of components in the scene) and it allocates the whole array every call. Rules of thumb:

That is exactly how the Pause System uses it: one call when the game pauses and one when it resumes, to collect the IPausables.

Order is not guaranteed. The returned list follows Unity's internal object order, which is not the hierarchy order and is not stable across runs. If you need a deterministic order, sort the list yourself (by name, by a priority field, …).


Testing Scene

Open Debug/InterfaceFounderScene.unity. Besides InterfaceFounderTest, which carries Mn_InterfaceFounderTest, the scene holds four objects with Mn_InterfaceFounderProbe on them: Probe Alpha, Probe Beta, Probe Nested (a child of Alpha) and Probe Disabled, which is switched off in the Hierarchy on purpose. Both methods sit on the component's context menu — right-click the header in the Inspector, no play mode.

  1. Find Probes — four objects come back, Probe Disabled among them, marked (inactive). This is the point of the scene: FindAllInterfaces<T> reaches objects that are switched off, which FindObjectsOfType does not do unless you ask it to. Nesting makes no difference either — Probe Nested is found as readily as its parent.
  2. Find Nothing — searching for an interface nothing implements returns a list of zero items, not null. Code that consumes the result can iterate it without a null check.

The one limit worth knowing: the search only covers loaded scenes. A prefab sitting in the project that has not been instantiated is not there, and that is the usual reason a list comes back shorter than expected.


Technical Info

Path Content
InterfaceFounder.cs The whole system: the static class InterfaceFinder

InterfaceFinder API: static List<T> FindAllInterfaces<T>() where T : class.

Implementation: Object.FindObjectsOfType<MonoBehaviour>(true) (the true is what includes inactive objects), then a single is T pass that builds the result list.


© 2026 Marcello De Bonis. All rights reserved

Real dependenciesOpen in the map →

Depends on 0

  • Standalone: no other module required.

Used by 1

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