3.4 KiB
3.4 KiB
Avatar Synchronization Scripts
This system allows you to synchronize Ready Player Me avatars in Unity by reading all transforms, rotations, and blendshapes from one avatar and applying them to another.
Files Created
AvatarDataWriter.cs- Reads avatar data and saves to JSONAvatarDataReader.cs- Reads JSON data and applies to target avatar
Prerequisites
- Newtonsoft.Json package must be installed in Unity
- Install via Package Manager: Window → Package Manager → "+" → Add package by name →
com.unity.nuget.newtonsoft-json
Setup Instructions
1. Writer Setup (Source Avatar)
- Add the
AvatarDataWritercomponent to your source Ready Player Me avatar GameObject - In the inspector:
- Avatar Root: Assign the root transform of your source avatar (if empty, uses the GameObject this script is on)
- File Name: Keep default
avatar_sync_data.jsonor change as needed - Write Every Frame: Check for real-time sync, uncheck for rate-limited updates
- Update Rate: If not writing every frame, set desired updates per second (default: 60)
2. Reader Setup (Target Avatar)
- Add the
AvatarDataReadercomponent to your target Ready Player Me avatar GameObject - In the inspector:
- Target Avatar Root: Assign the root transform of your target avatar
- File Name: Must match the writer's file name
- Read Every Frame: Check for real-time sync, uncheck for rate-limited updates
- Update Rate: If not reading every frame, set desired updates per second (default: 60)
- Smooth Transitions: Check for smooth interpolation, uncheck for instant updates
- Transition Speed: Speed of smooth transitions (default: 10)
- Show Debug Info: Check to see debug messages in console
How It Works
AvatarDataWriter
- Captures all transform data (position, rotation, scale) from the entire avatar hierarchy
- Captures all blendshape weights from SkinnedMeshRenderer components
- Saves this data as JSON to
Assets/Sync-Files/[filename].json - Updates every frame or at a specified rate
AvatarDataReader
- Reads the JSON file created by the writer
- Maps transform paths to find corresponding bones on the target avatar
- Applies transform data and blendshape weights to the target avatar
- Supports smooth transitions or instant updates
Important Notes
- File Path: Data is saved to
Assets/Sync-Files/directory (created automatically) - Avatar Structure: Both avatars should have similar bone hierarchies for best results
- Performance: Writing/reading every frame is intensive - consider rate limiting for better performance
- Blendshapes: Only works if both avatars have compatible blendshape setups
- Transform Paths: The system uses transform hierarchy paths to match bones between avatars
Troubleshooting
- Missing transforms: Check debug info to see which transforms couldn't be found
- Poor performance: Reduce update rate or disable "Every Frame" options
- Blendshapes not working: Ensure both avatars have SkinnedMeshRenderer components with blendshapes
- File not found: Check that the Sync-Files directory exists and the file names match
Example Usage
- Put
AvatarDataWriteron your player avatar - Put
AvatarDataReaderon your sync avatar - Play the scene - the sync avatar should now copy all movements and expressions from the player avatar in real-time!