PolymodHandler class is the central hub for Friday Night Funkin’s modding system, built on the Polymod framework. It handles mod discovery, loading, script initialization, and asset management.
Overview
PolymodHandler manages the complete mod lifecycle:- Scans and validates mods against API version requirements
- Loads mod assets and scripts in priority order
- Configures sandboxing and security restrictions
- Hot-reloads mods during development
- Registers scripted classes and modules
API Version
- API_VERSION: Returns the current game version (e.g., “0.8.0”)
- API_VERSION_RULE: Semantic versioning rule that defines compatible mod versions
- Mods must specify their
api_versionin_polymod_meta.json
Loading Mods
Load All Mods
Load Enabled Mods
Load Specific Mods
Load No Mods
Mod Discovery
Get All Mods
Get Enabled Mods
Get Loaded Mod IDs
Hot Reloading
- Clears all module and script caches
- Reloads all mods (uses
loadAllModsby default) - Reloads all game registries (songs, characters, stages, etc.)
- Calls
onCreateon all modules
Mod Lifecycle
When mods are loaded, PolymodHandler follows this sequence:- Scan: Discovers all mods in the mods folder
- Validate: Checks API version compatibility
- Initialize: Configures Polymod with security rules
- Load Assets: Loads and merges mod assets (images, audio, data)
- Parse Scripts: Parses
.hxcscripted class files - Register Classes: Registers scripted classes with the engine
- Load Modules: Instantiates module scripts
- Call onCreate: Dispatches CREATE event to all modules
Security & Sandboxing
PolymodHandler implements strict security rules to prevent malicious mods:Blacklisted Classes
These classes cannot be imported in mod scripts:Sys- System command executionsys.*- File system accesscpp.Lib- Native library loadinghaxe.Unserializer- Arbitrary class instantiationpolymod.*- Framework manipulation- API classes that could enable cheating
Sandboxed Alternatives
Safe alternatives are provided:Default Imports
Commonly used classes are automatically available:Mod Folder Structure
Mod Metadata
Every mod requires a_polymod_meta.json file:
Parse Rules
PolymodHandler configures how different file types are merged:Error Handling
Errors during mod loading are handled byPolymodErrorHandler:
- Script Parse Errors: Syntax errors in scripts show a popup
- Script Runtime Exceptions: Runtime errors show a popup
- Import Errors: Missing or blacklisted imports are reported
- Version Mismatches: Incompatible mods are skipped
Example: Checking Loaded Mods
Related
- Module System - Create persistent mods that respond to game events
- IScriptedClass - Interfaces for scripted classes
- Polymod Documentation - Full Polymod framework docs
