Reading time: ~25 minutes
@decorator syntax.
Table of Contents
@SerializeField
The@SerializeField decorator marks properties for serialization, allowing them to:
- Be saved and restored with scenes
- Be configured in scene descriptions
- Be editable in future editor tools
Usage
Supported Types
@SerializeField supports the following types:
Unsupported Types
The following cannot be serialized:Scene Configuration
Serialized fields can be set in scene descriptions:Getting Serialized State
@RequiresComponent
The@RequiresComponent decorator enforces that a component’s dependencies are present on the GameObject. If the required component is missing, it will be automatically added.
Usage
Multiple Requirements
You can stack multiple@RequiresComponent decorators:
Common Use Cases
Network Components
Physics Dependencies
Component Chains
Benefits
- Automatic Dependency Resolution: Required components are added automatically
- Type Safety: You can safely use non-null assertions (
!) - Documentation: Makes dependencies explicit in code
- Prevention: Avoids runtime errors from missing components
Note: Components are disallowed from having multiple instances by default in CORP. The @DisallowMultipleComponents decorator is reserved for future use.
@RPC.Method
The@RPC.Method decorator marks methods as Remote Procedure Calls, allowing them to be invoked across the network. See the Networking documentation for complete details.
Basic Usage
Configuration Options
Examples by Use Case
Client Request to Server
Server Notification to Clients
RPC with Return Value
Unreliable for Performance
Combining Decorators
Decorators can be combined for powerful component definitions:Network Component with Dependencies
Complex Character Controller
Best Practices
1. Always Use @RequiresComponent for Dependencies
2. Serialize Configuration, Not State
3. Use @DisallowMultipleComponents for Singletons
4. Configure RPCs Appropriately
4. Document Decorator Choices
Next Steps
- Advanced Topics: Learn about advanced patterns
- API Reference: Complete API documentation
- Examples: See decorators in action
Use decorators to create robust, well-structured components! 🎯