NSliceSpriteRenderer
Detailed reference for the NSliceSpriteRenderer component
NSliceSpriteRenderer Component
The NSliceSpriteRenderer component provides N-Slice functionality for 2D game environments. It extends the standard SpriteRenderer with advanced slicing capabilities.
Overview
NSliceSpriteRenderer is used in 2D game environments (not UI), providing essentially the same functionality as the N-Slice Image component. It divides images using the 9-slice method so that corners and borders remain undistorted when scaling to various sizes.
Key Features
- Dedicated to 2D Game Environment: Works in World Space, not UI Canvas
- N-Slice Compatible: Uses the same data format as N-Slice Image
- SpriteRenderer Extension: Includes standard sprite rendering features
- Real-time Size Adjustment: Size can be changed at runtime
⚠️ Important Warning
Size Adjustment in Scene View:
When you adjust object size by dragging with the mouse in Scene View, it changes the Transform Scale. This causes N-Slice borders to stretch as well, leading to unintended results.
- ❌ Scene View Dragging: Scale changes → Border distortion
- ✅ Inspector Size Field: Correct N-Slice behavior
Always adjust size using the Size field in the Inspector!
Component Reference
- N-Slice Data Assignment - Assigning and managing N-Slice data
- N-Slice Data Control - Fine-tuning N-Slice data
- Renderer Settings - Configuring basic renderer properties
- Size & Pivot - Managing size and pivot
- Sorting - Controlling rendering order
- Debugging - Troubleshooting tools
Differences from UI Image
Feature | NSliceSpriteRenderer | N-Slice Image |
---|---|---|
Environment | 2D World Space | UI Canvas |
Coordinate System | World Coordinates | UI/Screen Coordinates |
Size Units | Unity Units | Pixels |
Camera Dependency | Requires Camera | Canvas Rendering |
Sorting Method | Sorting Layer/Order | Canvas Hierarchy |
Usage Examples
Creating Game Objects
Common Use Cases
- Game UI Elements: Health bars, inventory slots, buttons
- Environment Objects: Platforms, walls, decorations
- Effects: Magic circles, portals, background effects
- Tiling: Repeatable background patterns