Reading time: ~25 minutes
GameObjects
GameObjects are the fundamental entities in your game world. Like Unity, every object in your game is represented by a GameObject. They act as containers for Components and form hierarchies through parent-child relationships.Creating GameObjects
GameObject Hierarchy
GameObjects can be organized in parent-child hierarchies:GameObject Transform
Each GameObject has a transform (CFrame) that defines its position and rotation:GameObject Lifecycle
GameObject Events
GameObjects fire events during their lifecycle:Components
Components define the behavior and data of GameObjects. All functionality in CORP is built using Components.The Component Base Class
TheComponent class is the abstract base for all components:
Component Lifecycle
Components follow a strict lifecycle:1. Construction
2. willStart() (Optional)
3. initialize()
4. onStart() (Required)
5. onPropertiesApplied() (Optional)
6. willRemove() (Required)
7. remove()
Accessing Other Components
Component Shortcuts
Components provide convenient shortcuts for common operations:Execution Order
Control the order in which components are initialized:Behaviors
Behavior is a specialized subclass of Component that adds serialization support. Most of your components should extend Behavior rather than Component.
Why Use Behavior?
- Serialization: Automatically serialize component state
- State Management: Track and restore component data
- Editor Support: Enable properties to be edited in the future editor
Creating a Behavior
Serializable Properties
Use the@SerializeField decorator to mark properties for serialization:
Serialization Support
Behavior supports serializing various types:State Serialization
Garbage Collection
CORP provides aCollector utility for managing resources:
Component Configuration
When adding components, you can configure their initial properties:Component Dependencies
Use the@RequiresComponent decorator to enforce dependencies:
Best Practices
1. Use Behaviors for Game Logic
2. Initialize in onStart(), Not Constructor
3. Clean Up Resources
4. Use Execution Order When Needed
5. Mark Serializable Fields
Next Steps
- Networking: Learn about multiplayer features
- Scene Management: Organize your game world
- Decorators: Use powerful component decorators
- Examples: See practical implementations
Understanding these core concepts will enable you to build complex games with CORP’s component-based architecture! 🎮