Coma is an Unreal Engine plugin that brings Unity-style [RequireComponent] functionality to Unreal. It provides automatic component dependency management and injection for actor components.
⚠️ Proof of Concept - Editor OnlyThis plugin works in the Unreal Editor but does not work in packaged/shipped builds. It is released as a proof of concept and learning resource.
📦 Legacy Code
This is old code written for Unreal Engine 4 and has not been updated or tested with Unreal Engine 5.
Developers coming from Unity are familiar with the [RequireComponent(typeof(T))] attribute, which automatically adds required components when you add a component to a GameObject. Unreal Engine doesn't have a built-in equivalent - Coma aims to fill that gap.
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(BoxCollider))]
public class MyComponent : MonoBehaviour {
// Rigidbody and BoxCollider are automatically added
}UCLASS()
class UMyComponent : public UManagedActorComponent {
GENERATED_BODY()
UPROPERTY(EditDefaultsOnly, Category = "Coma")
TMap<FName, TSubclassOf<UActorComponent>> Dependencies = {
{ TEXT("Physics"), UMyPhysicsComponent::StaticClass() }
};
};- Declarative Dependencies - Define component dependencies using a simple
TMapproperty - Automatic Creation - Dependency components are automatically created when the managed component is added
- Dependency Injection - Component references are automatically injected via Unreal's reflection system
- Lifecycle Management - Optionally destroy dependencies when the managed component is destroyed
- Blueprint Support - Works with Blueprint components in the editor
- Clone or download this repository
- Copy the
Comafolder to your project'sPluginsdirectory - Regenerate project files and build
Inherit from UManagedActorComponent and declare your dependencies:
#pragma once
#include "Components/ManagedActorComponent.h"
#include "MyManagedComponent.generated.h"
UCLASS()
class UMyManagedComponent : public UManagedActorComponent {
GENERATED_BODY()
public:
UMyManagedComponent() {
// Define dependencies
Dependencies.Add(TEXT("Health"), UHealthComponent::StaticClass());
Dependencies.Add(TEXT("Combat"), UCombatComponent::StaticClass());
}
};The UManagedActorComponent base class provides the following configuration:
| Property | Description |
|---|---|
Dependencies |
A map of display names to component classes that should be automatically created |
bDestroyDependenciesOnOwnDestruction |
When true, destroys all managed dependency components when this component is destroyed |
Coma can automatically inject component references into properties marked with injection metadata. This uses Unreal's reflection system to discover and populate component references.
The plugin is built around a Context pattern with specialized subjects:
- Creator - Creates dependency components
- Adder - Adds components to actors
- Injector - Injects component references into properties
- Remover - Removes components from actors
- Destroyer - Destroys components
- Reflector - Handles reflection-based dependency discovery
- LifetimeHooker - Manages component lifecycle hooks
The main API is exposed through the UComa class.
🚨 Critical: This plugin does not work in packaged builds.
The current implementation relies on editor-only functionality and reflection mechanisms that don't properly persist through the cooking/packaging process. This makes it unsuitable for production use.
Other limitations:
- Unreal Engine 4 only - Written for UE4, not updated for UE5
- Heavy reliance on Unreal's reflection system
- Editor module dependencies (
UnrealEd,BlueprintGraph) - Timing-sensitive lifecycle hooks that can behave differently outside the editor
The plugin includes a Blueprint example in Content/BlueprintExample/ demonstrating a chess board setup with various managed components:
BP_Board- Board component with dependenciesBP_Tile- Tile componentsBP_Pawn- Chess pawn with spawner dependencies
This is a proof of concept released for educational purposes. Feel free to fork and experiment, but be aware of the fundamental limitations with packaged builds.
If you find a way to make this work in shipped games, contributions are welcome!
MIT License - see LICENSE for details.
- Inspired by Unity's
[RequireComponent]attribute - Built for developers transitioning from Unity to Unreal Engine