ScriptableFactoryRegistry

Singleton ScriptableObject that serves as the central registry of all ScriptableFactory assets in the project. It auto-discovers factory assets in the editor and provides static query methods for retrieving factories by type at runtime.

Definition

Namespace: Paragon.Core.ScriptableFactory Assembly: Paragon.dll

[SingletonSettings(AssetPath = "Scriptable Factory Registry")]
public class ScriptableFactoryRegistry : SingletonScriptableObject<ScriptableFactoryRegistry>

Inheritance: ParagonScriptableObjectSingletonScriptableObject<ScriptableFactoryRegistry>ScriptableFactoryRegistry

Remarks

The registry maintains a Dictionary<Type, ScriptableFactory[]> that maps each concrete factory type to all its asset instances. This is populated automatically in the editor via [InitializeOnLoadMethod], which scans the AssetDatabase for all ScriptableFactory-derived assets.

At runtime, the ScriptableFactoryManager uses the registry to iterate and initialize all factories. Game code can also query the registry directly to find factories by type.

The registry is stored as a Resources asset at "Scriptable Factory Registry" so it persists across play mode and builds.

Quick Lookup

Goal
How

Get all factories

ScriptableFactoryRegistry.GetAllFactories()

Get factories of a specific type

ScriptableFactoryRegistry.GetAllFactoriesOfType<MyFactory>()

Get factories by runtime Type

ScriptableFactoryRegistry.GetAllFactoriesOfType(typeof(MyFactory))

Force refresh (editor only)

ScriptableFactoryRegistry.Initialize()

Methods

GetAllFactories

Returns all registered factory instances.

Returns: A flat enumerable of every ScriptableFactory in the registry across all types.

GetAllFactoriesOfType (Type)

Returns all factories whose type matches or derives from the given type.

Parameter
Type
Description

factoryType

Type

The factory type to filter by (uses IsOfType for inheritance-aware matching)

Returns: All factories whose concrete type matches or derives from factoryType.

GetAllFactoriesOfType<TFactory>

Generic convenience method that casts results to TFactory.

Returns: All matching factories cast to TFactory.

Initialize (Editor Only)

Scans the AssetDatabase for all ScriptableFactory assets and rebuilds the registry table. Runs automatically via [InitializeOnLoadMethod].

circle-info

This method is only available in the Unity Editor (#if UNITY_EDITOR). At runtime, the registry is loaded from the pre-built Resources asset.

Examples

Querying Factories at Runtime

See Also

Last updated