Skip to main content
Reading time: ~25 minutes
CORP provides several powerful decorators to enhance your components with additional functionality and constraints. Decorators are applied using TypeScript’s @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

  1. Automatic Dependency Resolution: Required components are added automatically
  2. Type Safety: You can safely use non-null assertions (!)
  3. Documentation: Makes dependencies explicit in code
  4. 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


Use decorators to create robust, well-structured components! 🎯