Open Source Plugin • Real-Time CSG

Dynamic Geometry Zones for Unreal Engine

Real-time Constructive Solid Geometry plugin that dynamically clips objects as they move in and out of specified areas. Inspired by Skyward Sword's Timegate crystals, solving the "half-in, half-out" problem with smooth geometry transitions.

The Problem

Area-Based Visibility Limitations

Traditional area-based effects (like Skyward Sword's Timegate crystals) use simple show/hide logic. When objects cross zone boundaries, they either pop in/out instantly or have jarring transitions. This breaks immersion and creates visual artifacts for large objects spanning boundaries.

Dynamic Geometry Clipping

Real-time CSG system that continuously regenerates mesh geometry and collision as objects move. Objects smoothly appear/disappear with proper clipped geometry, maintaining visual coherence and physical accuracy even when partially inside zones.

Real-Time
CSG Operations
0
Pop-in Artifacts
Area Configurations
Multi
Material Support

Gameplay Applications

Skyward Sword Timegates

Time manipulation crystals

Hit crystals to reveal different time periods. Objects smoothly transition between present (desert) and past (lush) versions as they move in/out of the temporal field.

A Hat in Time Bells

Platform visibility control

Ring bells to enable/disable platforms in specific radii. Players must position themselves strategically as geometry phases in and out of existence.

Portal-Style Mechanics

Dimensional rifts and zones

Create dimensional tears where different realities overlap. Objects exist in multiple dimensions simultaneously, visible only in specific zones.

Puzzle Design

Area-based logical challenges

Design puzzles requiring players to manipulate multiple zones to create paths, reveal hidden objects, or access previously unreachable areas.

Technical Architecture

The system uses Unreal's GeometryScripting plugin for real-time CSG operations, combined with custom collision detection and material management.

CSG Processing Pipeline

Collision Detection
Geometry Analysis
CSG Operations
Mesh Updates

Core Components

  • CSGBaseComponent: Base class providing core CSG functionality and material management
  • CSGStaticMeshComponent: Implementation for static mesh objects with "Allow CPU Access" requirement
  • CSGArea Components: Invisible volume triggers that define clipping boundaries
  • Custom Collision Channel: Configurable collision channel for efficient area detection
  • GeometryScripting Integration: Real-time mesh modification using Unreal's built-in geometry tools
  • Material Array System: Support for multiple material slots with automatic cut-surface material assignment
Component Setup Example
// CSG-enabled actor in your level
UCLASS()
class YOURGAME_API ACSGActor : public AActor
{
    GENERATED_BODY()

public:
    ACSGActor()
    {
        // Create the CSG static mesh component
        CSGMesh = CreateDefaultSubobject<UCSGStaticMeshComponent>(TEXT("CSGMesh"));
        RootComponent = CSGMesh;

        // Configure collision for CSG detection
        CollisionComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Collision"));
        CollisionComponent->SetCollisionResponseToChannel(ECC_GameTraceChannel1, ECR_Block);
        CollisionComponent->AttachToComponent(RootComponent,
            FAttachmentTransformRules::KeepRelativeTransform);
    }

protected:
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
    class UCSGStaticMeshComponent* CSGMesh;

    UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
    class UStaticMeshComponent* CollisionComponent;
};

Plugin Configuration

⚙️

Project Settings

Collision Channel: Custom trace channel for CSG detection
Default Area Material: Editor visualization material for CSG zones

🎨

CSGBase Component

Do Reverse CSG: Show inside vs outside zones
Materials Array: Multi-material support
CSG Material: Material for cut surfaces

📦

CSGStatic Mesh

Mesh Setting: Static mesh with CPU access enabled
Allow CPU Access: Required for real-time geometry modification

🔧

Custom Components

GetVisualMesh(): Override for custom geometry generation
GetCollisionMesh(): Custom collision geometry creation

Creating Custom CSG Components
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class YOURGAME_API UCustomCSGComponent : public UCSGBaseComponent
{
    GENERATED_BODY()

public:
    UCustomCSGComponent();

protected:
    // Override to provide custom visual geometry
    virtual void GetVisualMesh(UDynamicMesh* OutMesh) override
    {
        // Generate your custom geometry here
        // Could be procedural, skeletal mesh conversion, etc.

        // Example: Create a procedural box
        FGeometryScriptPrimitiveOptions PrimOptions;
        UGeometryScriptLibrary_MeshPrimitiveFunctions::AppendBox(
            OutMesh, PrimOptions, FTransform::Identity,
            BoxSize.X, BoxSize.Y, BoxSize.Z
        );
    }

    // Override to provide custom collision geometry
    virtual void GetCollisionMesh(UDynamicMesh* OutMesh) override
    {
        // Generate collision mesh (can be same as visual or optimized version)
        GetVisualMesh(OutMesh);
    }

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Custom CSG")
    FVector BoxSize = FVector(100.0f, 100.0f, 100.0f);
};

Performance Considerations

Optimized for Simple Geometry

The system works excellently with simple shapes and moderate polygon counts. CSG operations are performed efficiently using Unreal's GeometryScripting, and collision detection uses custom channels for optimal performance.

Complex Mesh Limitations

Performance degrades with high-polygon meshes due to real-time geometry generation requirements. The "Allow CPU Access" requirement also impacts memory usage. Currently limited to static meshes (skeletal mesh support possible but not implemented due to complexity).

Performance Optimization Strategies

  • LOD Integration: Use simplified geometry for CSG operations while maintaining visual fidelity
  • Area Culling: Only perform CSG on objects actually overlapping with zones
  • Update Frequency: Configurable update rates to balance smoothness vs. performance
  • Geometry Caching: Cache CSG results for static scenarios to avoid redundant calculations
  • Material Optimization: Efficient material slot management to minimize draw calls
  • Collision Optimization: Separate visual and collision mesh complexity for better performance

Known Limitations

  • CPU Access Requirement: Static meshes must have "Allow CPU Access" enabled, increasing memory usage
  • Real-time Generation: Collision and visual geometry generated on-demand, impacting performance with complex meshes
  • Static Mesh Only: Currently supports static meshes; skeletal mesh support requires additional development
  • Multiple Area Overlap: Works correctly but can be expensive with many overlapping zones
  • Custom Collision: Limited to Unreal's collision system; no custom collision detection alternatives available

Easy Integration

Step-by-Step Setup
# 1. Install the plugin
# Download from GitHub and place in your project's Plugins folder

# 2. Enable required plugins
# - CSGArea (this plugin)
# - GeometryScripting (Unreal built-in)

# 3. Configure project settings
# Project Settings -> Plugins -> CSGArea Settings
# - Set custom collision channel
# - Configure default area material

# 4. Prepare your static meshes
# For any mesh you want to use with CSG:
# - Open the Static Mesh asset
# - Enable "Allow CPU Access" in Build Settings
# - Save the asset

# 5. Create CSG actors in your level
# - Add actors with CSGStaticMeshComponent
# - Add collision components using the configured collision channel
# - Set up your materials array and CSG material

# 6. Create CSG areas
# - Place CSGArea actors to define zones
# - Configure "Do Reverse CSG" as needed
# - Test the dynamic geometry transitions

Integration Benefits

  • Plugin-Based: Drop into any Unreal project without engine modifications
  • Component-Based Design: Easily add CSG functionality to existing actors
  • Blueprint Friendly: All settings exposed to Blueprint system for designer control
  • Editor Integration: Visual area representation and configuration in Unreal Editor
  • Extensible Architecture: Custom components can override geometry generation for specific needs
  • Standard Workflows: Works with existing Unreal material and collision systems

Ready to Create Dynamic Worlds?

The CSG Area plugin opens up new possibilities for area-based gameplay mechanics. From time manipulation to dimensional puzzles, create smooth transitions that maintain immersion and visual coherence.