Ren'Py build.classify rules for dynamically loaded assets that vanish in production builds
0 reputation · 19 Sept 2024, 16:13 UTC
0 reputation · 19 Sept 2024, 16:13 UTC
I am setting up the build.classify() rules in options.rpy for a Ren'Py 8.x project that loads some images and audio through computed filenames (via renpy.file() and string-built paths) rather than static image statements. The game runs correctly from the SDK, but after building a distribution some of those assets are missing at runtime.
My understanding is that files not matched by any classify pattern are silently excluded from the .rpa archives, and that static analysis does not see dynamically constructed names. I also develop on a case-insensitive filesystem, while the deployed targets (Linux, Android) are case-sensitive, so a path like Images/bg.png versus images/bg.png may work locally and fail after packaging.
The unresolved decision is how to make the build fail loudly instead of shipping silently broken: Ren'Py does not appear to warn at build time about unclassified-but-referenced files or case mismatches.
33275 reputation · 19 Sept 2024, 17:41 UTC
To ensure dynamically loaded assets are included in your production build, you must define a build.classify rule using a regular expression that matches the entire directory path. Because Ren'Py's static analysis cannot detect strings built at runtime, any file not explicitly matched by a classification rule is excluded from the .rpa archives.
You can force the inclusion of an entire folder by using a regex pattern in options.rpy. This ensures that every file within that path is packaged, regardless of whether it is referenced in a script.
# Include everything in the 'game/images/dynamic/' folder into the 'images' archive
build.classify('game/images/dynamic/.*', 'images')
# If your assets are in a top-level folder like 'game/audio/music/'
build.classify('game/audio/music/.*', 'audio')
Ren'Py does not currently provide a build-time "strict mode" to fail the build when assets are unclassified or when filename casing is mismatched. The Check Script (Lint) tool primarily validates static references and will not catch errors in dynamically constructed paths.
"Images/bg.png" works on Windows/macOS (case-insensitive) but will fail on Linux or Android (case-sensitive) once packed into an archive.While omitting a file from all build.classify rules keeps it as a loose file in the distribution, this is not recommended for dynamic assets. Loose files are exposed to the user and are more prone to platform-specific path resolution errors. Classifying them into an .rpa archive is the supported approach for production stability.
.rpa file.Diagnostic Note: Are you using absolute paths or paths relative to the game/ directory in your renpy.file() calls? This determines whether your build.classify regex needs to start with 'game/' or the subfolder name.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.