n2c-code-generator

star 0

Generate C++ header and implementation from N2C JSON with project context. Sub-agent of n2c-orchestrator.

buihuuloc By buihuuloc schedule Updated 3/2/2026

name: n2c-code-generator description: Generate C++ header and implementation from N2C JSON with project context. Sub-agent of n2c-orchestrator.

N2C Code Generator Agent

Generates C++ code from NodeToCode JSON using project-verified context.

Input Contract

{
  "jsonPath": "G:/s2/Saved/NodeToCode/Export/GA_Jump.json",
  "context": {
    "includeMap": { ... },
    "baseClassContext": { ... },
    "apiPatterns": { ... },
    "namingConventions": { ... },
    "potentialConflicts": [ ... ]
  },
  "outputClassName": "UGA_Jump",
  "moduleName": "S2"
}

Output Contract

Success:

{
  "success": true,
  "header": "// Full .h file content...",
  "implementation": "// Full .cpp file content...",
  "notes": [
    "Used K2_OverrideRuntimeData_Implementation signature from base class",
    "Renamed AnimationData to LocalAnimData to avoid shadowing",
    "Added GameplayTasks to Build.cs dependencies"
  ],
  "buildDependencies": ["GameplayAbilities", "GameplayTags", "GameplayTasks"]
}

Failure:

{
  "success": false,
  "errorCode": "GENERATION_FAILED",
  "errorMessage": "Failed to generate code for graph EventGraph",
  "partialOutput": { ... }
}

Execution Steps

Step 1: Load Inputs

Read N2C JSON and context:

n2c_json = read_json(json_path)
context = input.context

include_map = context.includeMap
base_class = context.baseClassContext
api_patterns = context.apiPatterns
conflicts = context.potentialConflicts

Step 2: Assemble Generation Prompt

Build the prompt with all context:

<projectContext>
  <includeMap>
    {
      "USipherGameplayAbilityRuntime": "GameplayAbilities/SipherGameplayAbilityRuntime.h",
      "FSipherAbilityData_Animation": "GameplayAbilities/AbilityData/SipherAbilityData_Animation.h"
    }
  </includeMap>

  <baseClassSignatures>
    {
      "className": "USipherGameplayAbilityRuntime",
      "virtualMethods": [
        {
          "name": "K2_OverrideRuntimeData_Implementation",
          "signature": "virtual bool K2_OverrideRuntimeData_Implementation(TInstancedStruct<FSipherGenericAbilityData>& OverridenData)"
        }
      ]
    }
  </baseClassSignatures>

  <apiPatterns>
    - UAITask_MoveTo: Use OnMoveTaskFinished.AddUObject, NOT OnMoveFinished.AddDynamic
    - AbilityWaitDelay: Use UAbilityTask_WaitDelay::WaitDelay, NOT UGameplayTask_WaitDelay
    - TSoftObjectPtr: Call .LoadSynchronous() when assigning to raw pointer
    - K2Functions: Use native functions, NOT K2_ wrappers
  </apiPatterns>

  <namingConventions>
    - Actor classes: ASipher{Name}
    - Components: USipher{Name}Component
    - Structs: FSipher{Name}
    - Avoid shadowing: {conflicts}
  </namingConventions>

  <avoidShadowing>
    Base class has these members - do NOT use as local variable names:
    - AnimationData
    - AbilityData
  </avoidShadowing>
</projectContext>

<nodeToCodeJson>
  {Full N2C JSON content}
</nodeToCodeJson>

<task>
  Convert this Blueprint to C++ following the project context above.

  CRITICAL RULES:
  1. Use ONLY include paths from includeMap - do not guess
  2. Match base class method signatures EXACTLY
  3. Follow apiPatterns for UE5.7 compatibility
  4. Rename local variables that would shadow base class members
  5. Structure: .generated.h last in header, own header first in .cpp
</task>

Step 3: Generate Code

Use the CodeGen_CPP.md system prompt to generate code.

Parse the LLM response:

{
  "graphs": [
    {
      "graph_name": "ActivateAbility",
      "graph_type": "Function",
      "graph_class": "UGA_Jump",
      "code": {
        "graphDeclaration": "...",
        "graphImplementation": "...",
        "implementationNotes": "..."
      }
    }
  ]
}

Step 4: Assemble Full Files

Combine all graph outputs into complete .h and .cpp files:

Header Assembly:

// Copyright (c) 2025 Sipher. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "{BaseClassInclude}"
// Other includes from graphs...
#include "{ClassName}.generated.h"

// Forward declarations...

/**
 * @brief {BlueprintName} converted from Blueprint
 * @note Auto-generated by NodeToCode
 */
UCLASS()
class {MODULE}_API {ClassName} : public {BaseClass}
{
    GENERATED_BODY()

public:
    {ClassName}();

    // Graph declarations...
    {graphDeclarations}

protected:
    // Protected members...

private:
    // Private members...
};

Implementation Assembly:

// Copyright (c) 2025 Sipher. All Rights Reserved.

#include "{ClassName}.h"
// Other includes...

{ClassName}::{ClassName}()
{
    // Constructor from graphs
}

// Graph implementations...
{graphImplementations}

Step 5: Collect Build Dependencies

Parse includes to determine Build.cs dependencies:

build_dependencies = set()

# Map include paths to module names
include_to_module = {
    "GameplayAbilities/": "GameplayAbilities",
    "GameplayTags/": "GameplayTags",
    "GameplayTasks/": "GameplayTasks",
    "AIModule/": "AIModule",
    "NavigationSystem/": "NavigationSystem"
}

for include in all_includes:
    for pattern, module in include_to_module.items():
        if pattern in include:
            build_dependencies.add(module)

Step 6: Return Result

{
  "success": true,
  "header": "// Full assembled .h content",
  "implementation": "// Full assembled .cpp content",
  "notes": [
    "Used K2_OverrideRuntimeData_Implementation signature from base class",
    "Renamed AnimationData to LocalAnimData to avoid shadowing"
  ],
  "buildDependencies": ["GameplayAbilities", "GameplayTags"]
}

Code Quality Rules

Include Order (Header)

  1. CoreMinimal.h
  2. Base class header
  3. Other dependencies (alphabetical)
  4. {ClassName}.generated.h (ALWAYS LAST)

Include Order (Implementation)

  1. Own header {ClassName}.h (ALWAYS FIRST)
  2. Other dependencies (alphabetical)

Code Style

  • Braces on new line
  • Tabs for indentation
  • nullptr not NULL
  • Explicit this-> for member access in lambdas
  • const correctness

UE5.7 Compatibility

  • No K2_ function calls
  • Correct delegate binding methods
  • Correct AbilityTask classes
  • TSoftObjectPtr loading

Handling Complex Nodes

Latent/Async Nodes

// Blueprint latent node becomes:
UAbilityTask_WaitDelay* DelayTask = UAbilityTask_WaitDelay::WaitDelay(this, Duration);
DelayTask->OnFinish.AddDynamic(this, &ThisClass::OnDelayFinished);
DelayTask->ReadyForActivation();

ForEachLoop Nodes

// Blueprint ForEachLoop becomes:
for (const auto& Element : ArrayToIterate)
{
    // Loop body
}

Branch Nodes

// Blueprint Branch becomes:
if (Condition)
{
    // True branch
}
else
{
    // False branch
}

Sequence Nodes

// Blueprint Sequence becomes sequential statements:
// Then 0
DoFirstThing();

// Then 1
DoSecondThing();

// Then 2
DoThirdThing();
Install via CLI
npx skills add https://github.com/buihuuloc/universal-ue-skills --skill n2c-code-generator
Repository Details
star Stars 0
call_split Forks 0
navigation Branch main
article Path SKILL.md
More from Creator