MClassRegistry
- Module
- Core
- Header
#include "Core/MClassRegistry.h"- Namespace
Mowo
Type aliases
| Alias | Description |
|---|---|
using FNameResolver = MClass* (*)(FName name) | Classes that exist on disk but are registered only when first needed (Visual Scripting: the class index knows the file, nothing has parsed it). A FindByName miss gives the resolver one chance to register the name; GetAllClasses first asks for every pending class, because a caller enumerating classes (a palette, a node catalogue) must see them all. Neither hook re-enters itself on the same thread. |
using FPendingMaterializer = void (*)() |
Constructors
| Signature | Name | Description |
|---|---|---|
MClassRegistry(const MClassRegistry&) = delete | MClassRegistry |
Public functions
| Returns | Name | Description |
|---|---|---|
MClassRegistry& | Get | |
MClassRegistry& | operator= | |
bool | Register | Called by codegen's static-init for each MCLASS-annotated type. |
bool | Unregister | Hot-reload path: drop every MClass whose pointer lives inside a module that is about to unload. |
bool | RegisterNamed | Data-driven classes have no C++ type, so no std::type_index to key on — Visual Script builds an MClass at runtime from a .vscript asset and registers it BY NAME here so SpawnActorByClass / FindByName resolve it like any codegen class. |
bool | UnregisterNamed | Drop a previously RegisterNamed'd class. |
size_t | UnregisterAllInModule | Drop every MClass whose static instance lives inside the given module binary (handle from FModuleManager::GetModuleHandle). |
bool | IsClassInModule | True when the MClass static instance lives inside the given module binary — the hot-reload orchestrator's actor filter. |
MClass* | Find | Lookup. |
MClass* | FindByName | Name lookup — MClass::GetSuperClass() resolves superClassName through this (the super's MClass instance lives in another TU / module, so codegen can't link the pointer at static init). |
MClass* | FindForType | |
size_t | Num | |
uint32_t | Revision | Moves on every change to the set of classes (register, unregister, a module dropping its classes). |
std::vector<MClass*> | GetAllClasses | Snapshot of every registered MClass (codegen + named/synthetic). |
uint32_t | Epoch | The same counter as Revision(), under the name MObject::GetClass keys its per-object cache on. |
void | SetLazyHooks |
Function details
MClassRegistry
MClassRegistry(const MClassRegistry&) = deleteGet
static MClassRegistry& Get()operator=
MClassRegistry& operator=(const MClassRegistry&) = deleteRegister
bool Register(std::type_index typeId, MClass* cls)Called by codegen's static-init for each MCLASS-annotated type. Returns true on insert; false for nullptr or a duplicate typeid (two MCLASS-annotated headers for the same C++ type — invalid input, first registration wins).
Unregister
bool Unregister(std::type_index typeId)Hot-reload path: drop every MClass whose pointer lives inside a module that is about to unload.
RegisterNamed
bool RegisterNamed(FName name, MClass* cls)Data-driven classes have no C++ type, so no std::type_index to key on — Visual Script builds an MClass at runtime from a .vscript asset and registers it BY NAME here so SpawnActorByClass / FindByName resolve it like any codegen class. The registry does NOT own the MClass (the caller, e.g. VisualScriptClassRegistry, owns the storage). FindByName searches these too. Fails on a name already taken (by a codegen or another named class).
UnregisterNamed
bool UnregisterNamed(FName name)Drop a previously RegisterNamed'd class. Returns true if removed.
UnregisterAllInModule
size_t UnregisterAllInModule(void* moduleHandle)Drop every MClass whose static instance lives inside the given module binary (handle from FModuleManager::GetModuleHandle). Attribution is by ADDRESS — generated MClass instances are statics in the module's .refl.cpp TUs, so their addresses fall inside the module image. Call BEFORE the library is freed. Also clears cached superClass links pointing into the dropped set (other modules' classes may have lazily linked to them). Returns the number of classes dropped.
IsClassInModule
static bool IsClassInModule(const MClass* cls, void* moduleHandle)True when the MClass static instance lives inside the given module binary — the hot-reload orchestrator's actor filter.
Find
MClass* Find(std::type_index typeId) constLookup. Returns nullptr if not registered.
FindByName
MClass* FindByName(FName name) constName lookup — MClass::GetSuperClass() resolves superClassName through this (the super's MClass instance lives in another TU / module, so codegen can't link the pointer at static init). Linear scan over the registry: called once per class thanks to the GetSuperClass cache, and the registry is small (tens of classes). Returns nullptr if not registered.
FindForType
template<typename T> MClass* FindForType() constNum
size_t Num() constRevision
uint32_t Revision() constMoves on every change to the set of classes (register, unregister, a module dropping its classes). A caller caching name lookups — Visual Scripting resolves a reflected call by name on every invocation — keys its cache on this, because a hot-reloaded module frees the FMFunctionInfo a stale entry would still point at.
GetAllClasses
std::vector<MClass*> GetAllClasses() constSnapshot of every registered MClass (codegen + named/synthetic). Copies the pointer set under the shared lock; the MClass instances are static (codegen) or owner-managed (named), so the pointers stay valid until module unload.
Epoch
uint32_t Epoch() constThe same counter as Revision(), under the name MObject::GetClass keys its per-object cache on. Never 0, so a zeroed cache stamp never matches.
SetLazyHooks
void SetLazyHooks(FNameResolver resolver, FPendingMaterializer materializer)