A Unity Editor extension that bulk-copies components matching a regular expression pattern to objects in identical hierarchical positions.
If you use VRChat Creator Companion (VCC), follow these steps:
- Visit the Listing page
- Click "Add to VCC" to add the repository
- Open your project in VCC and add
CopyComponentsByRegexvia "Manage Project"
- Open
Window->Package Managerfrom Unity menu bar - Click the
+button in the top left of Package Manager and selectAdd package from git URL - Paste
https://github.com/Taremin/CopyComponentsByRegex.gitand clickAdd
Download this repository's ZIP file and copy extracted contents into your assets folder.
Make sure to copy the Editor folder as-is.
This is due to Unity's specification that "scripts in the Editor folder are only valid in the editor and ignored during game execution."
(Reference: Special Folder Names - Unity Manual)
If you only copy *.cs files from the Editor folder, errors will occur during runtime.
- Select the source object in the Hierarchy
- Right-click and select
Copy Components By Regexfrom the context menu - In the
Copy Components By Regexwindow, enter a regex pattern matching the components to copy (e.g.,Dynamicto copyDynamic BoneandDynamic Bone Collider) - Click the
Copybutton - Select the destination object in the Hierarchy
- Click the
Pastebutton
To check component names for writing regex patterns, expand the "Components" section. Click the "Copy" button next to a component name to copy it to your clipboard.
Object references within copied objects and components (like Dynamic Bone's root) are automatically replaced with destination objects and components.
However, references to components outside the copy range remain unchanged.
Structure similarity is determined by object names, so issues may occur with same-named child objects under the same parent. Additionally, even if structures aren't identical, the tool tries to traverse matching child names, allowing copies even with added bones.
When source and destination have different object names (e.g., VRoid Studio's J_Bip_C_Head vs standard Head), use Name Mapping Rules to bridge naming differences.
Two types of rules are available:
-
Regex Rules: Transform names using arbitrary regex patterns
- e.g.,
J_Bip_C_(.+)→$1(removes VRM prefix)
- e.g.,
-
Humanoid Bone Rules: Dynamically match using Unity Humanoid rig mapping info
- Both source and destination must be configured as Humanoid rigs
- Supported groups: All, Head, Neck, Chest, Spine, Hips, Left Arm, Right Arm, Left Leg, Right Leg, Left Fingers, Right Fingers
See Name Mapping Guide for details.
For Cloth component copies between identical models with matching vertex counts, Constraints are simply copied (fast).
For different vertex counts or significantly different shapes, check Cloth NNS (Nearest Neighbor) (slower).
Note: Due to Unity's Cloth vertex coordinate issues during initialization, add a Cloth component to the destination beforehand.
See https://taremin.github.io/2018/06/12/4-CopyComponentsByRegex_%E3%81%AE%E7%B0%A1%E5%8D%98%E3%81%AA%E4%BD%BF%E3%81%84%E6%96%B9%E3%81%A8%E8%AA%AC%E6%98%8E/ (Japanese) for more detailed explanations.
- Unity 2019.2 or later
- Open
Window->General->Test Runnerin Unity Editor - Select the
EditModetab - Tests under
CopyComponentsByRegex.Testsassembly will appear - Click
Run Allto execute tests
Unity.exe -runTests -batchmode -projectPath <project path> -testPlatform EditMode -testResults results.xml- KDTreeTests: Tests KD-tree nearest neighbor search
- CopyComponentsByRegexTests: Tests basic data structures (TreeItem, ModificationEntry, etc.)
- IntegrationTests: Complex hierarchy integration tests
- GetChildren, CopyWalkdown, MergeWalkdown core functionality
- Regex matching, recursive hierarchy processing
- HumanoidBone replacement rule matching (e.g., hips→siri bone mapping)
- NameMatcherTests: Name matching functionality
- Regex rule name transformations
- HumanoidBone dynamic mapping
- Child object search with replacement rules
- ModificationReportPopupTests: Modification report display tests
- Replacement rule application in MergeWalkdown
- Object search with HumanoidBone rules
- BugReportExporterTests: Bug report export tests
- Hierarchy structure JSON output
- PathUtilityTests: Path utility functionality
- Relative/absolute path retrieval
- Package path resolution
- LocalizationTests: Internationalization functionality
- Language switching
- Key consistency across languages
This tool supports both English and Japanese. You can change the language from the dropdown at the top of the editor window.
- English: UI displays in English
- 日本語: UI displays in Japanese
- System: Automatically detects OS language
CopyComponentsByRegex uses modified code from:
- KDTree.cs - A Stark, September 2009. https://forum.unity.com/threads/point-nearest-neighbour-search-class.29923/