Reading time: ~20 minutes
Table of Contents
What are Macros?
Macros are classes that extendMacro and implement a transformInstanceHierarchy() method. When CORP encounters an instance tagged with a macro name, it invokes that macro to transform the instance hierarchy.
Key Features
- Instance Transformation: Modify or replace instances during loading
- Procedural Generation: Generate complex hierarchies from simple markers
- Template Expansion: Convert placeholder instances into full structures
- Dynamic Configuration: Create instances based on game state or data
How Macros Work
- You create instances in Workspace or scenes
- Tag them with a macro name (e.g.,
%spawn_point_macro) - During loading, CORP applies the macro transformation
- The macro returns the transformed instance hierarchy
Creating a Macro
Basic Macro Class
Macro with Configuration
Read attributes from the tagged instance:Complex Macro with Children
Process child instances and generate complex structures:Using Macros
Tagging Instances in Studio
- Create an instance (Part, Model, Folder, etc.)
- Add a tag using the Tag Editor plugin
- Use the format
%macro_name(e.g.,%spawn_point_macro)
Programmatic Application
Macros are automatically applied when loading from workspace:Getting Macro Information
Macro Registration
Macros must be registered in your Gamepack’s exports to be available.Registering in Gamepack
Createexports/macros.ts:
Naming Convention: Always use snake_case for macro mapping names. This ensures consistency across your codebase and makes tags easy to read.
Common Use Cases
1. Spawn Point Generation
2. Prefab Instantiation
3. Procedural Environment
4. Dynamic Layout
Best Practices
1. Use snake_case for Names
2. Clean Up Original Instances
Always destroy the original instance after transformation:3. Handle Edge Cases
4. Use Attributes for Configuration
5. Preserve Hierarchy
Maintain parent relationships when transforming:6. Document Your Macros
Next Steps
- ScriptableObjects: Learn about data assets
- Unreal System: Understand Gamepack integration
- Scene Management: Learn about scenes and instance hierarchies
- Examples: See complete implementations
Master macros for powerful procedural generation and instance transformation! 🔧