UGTK cat mascotUGTKengine within an engine Request access

UGTK / Toolkit / Component Module / Generic Component Completed

Component Module — UGTK

Generic Component

Summary

Mn_UGTKComponent is the abstract base class every UGTK "component" derives from. It gives a component one thing the engine does not: a guaranteed owner, that is the GameObject the component acts upon.

The idea is that a component lives on its own child GameObject, hanging under the object it modifies — a Damage object under the enemy, a Follow object under the camera. That way a single actor can carry several components without them fighting over the same GameObject, and each of them can be enabled, disabled or removed on its own.


Content


Modules Dependencies

None. A single abstract class with no UGTK reference. It is a dependency of several other modules (Damage System, Follow System, PingPong Movement) rather than the other way around.


Setup

There is nothing to add to a scene and no prefab, so there is no GIF: the class is only useful as a base to derive from.

public class Mn_MyComponent : Mn_UGTKComponent
{
    protected override void Awake()
    {
        base.Awake();          // do not forget this: it is what resolves the owner
        Debug.Log($"My owner is {Owner.name}");
    }
}

How To Use

Owner is the whole API. Reading it returns the parent GameObject, resolving it on first access; assigning it reparents this component under the new owner:

myComponent.Owner = someEnemy;   // the component's GameObject becomes a child of someEnemy
GameObject target = myComponent.Owner;

Two serialized options:

Good to know:


Testing Scene

Open Debug/GenericComponentScene.unity. Two empty objects, First Owner and Second Owner, and under the first one a third carrying Mn_GenericComponentTest together with Mn_DemoComponent — the smallest possible concrete subclass, which adds nothing at all, so everything the scene shows comes from Mn_UGTKComponent itself. Both methods are on the context menu: right-click the header in the Inspector, no play mode.

  1. Read Owner — returns First Owner. Nothing ever assigned it: the getter adopts the current parent rather than returning null. Code that checks if (component.Owner == null) before assigning will therefore never take that branch.
  2. Assign Owner — the output reports the parent going from First Owner to Second Owner. Assigning the property does not only store a reference: it reparents the GameObject. Worth knowing before assigning it in Awake on an object whose position matters.
  3. Read Owner again — now Second Owner, from the field this time rather than from the parent.
  4. Rename The Object — the object becomes Renamed By Hand. With Manage Name on, the component puts its own type name back the next time Unity validates it: touch any field of the component and the name returns to DemoComponent. Turn Manage Name off if you want your own names to stick.

One thing the scene cannot show but which follows from the same design: the owner is stored in a private field that is not serialised. It survives while the editor is running, and comes back null after a domain reload — at which point the getter silently adopts the parent again. If the owner is genuinely something other than the parent, assign it in code every time rather than once.


Technical Info

Path Content
Scripts/Runtime/Mn_UGTKComponent.cs The abstract class: Owner (get resolves, set reparents), ChangeOwner, the Awake that resolves the owner, and the OnValidate that manages the name

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