Skip to content

Commit 5ab4777

Browse files
committed
update: README.md and try out the Migrate module from another project
1 parent 21291b9 commit 5ab4777

File tree

9 files changed

+300
-7
lines changed

9 files changed

+300
-7
lines changed

FirstModule.uproject

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
"Name": "Manual",
1919
"Type": "Runtime",
2020
"LoadingPhase": "Default"
21+
},
22+
{
23+
"Name": "Migrate",
24+
"Type": "Runtime",
25+
"LoadingPhase": "Default"
2126
}
2227
],
2328
"Plugins": [

README.md

Lines changed: 188 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
2. [Module Structure Analysis](#module-structure-analysis)
2020
3. [Creating Modules Manually](#creating-modules-manually)
2121
4. [Creating Modules with IDE](#creating-modules-with-ide)
22-
5. [Module Dependencies](#module-dependencies)
23-
6. [Best Practices](#best-practices)
24-
7. [Common Issues and Solutions](#common-issues-and-solutions)
25-
8. [References](#references)
26-
9. [Contributing](#contributing)
22+
5. [Migrating Modules](#migrating-modules)
23+
6. [Module Dependencies](#module-dependencies)
24+
7. [Best Practices](#best-practices)
25+
8. [Common Issues and Solutions](#common-issues-and-solutions)
26+
9. [References](#references)
27+
10. [Contributing](#contributing)
2728

2829
## What is an Unreal Module
2930

@@ -89,6 +90,14 @@ FirstModule/Source/
8990
│ ├── ManualExposed.cpp
9091
│ ├── ManualInternal.cpp
9192
│ └── ManualInternal.h # Internal implementation
93+
├── Migrate/ # Migrated module (example)
94+
│ ├── Migrate.Build.cs
95+
│ ├── Public/
96+
│ │ ├── Migrate.h
97+
│ │ └── MigrateActor.h
98+
│ └── Private/
99+
│ ├── Migrate.cpp
100+
│ └── MigrateActor.cpp
92101
└── FirstModule/ # Main game module
93102
├── FirstModule.Build.cs
94103
├── FirstModule.cpp
@@ -383,6 +392,180 @@ IMPLEMENT_MODULE(FAutoModule, Auto)
383392
<img width="100%" src="https://github.com/user-attachments/assets/750c4cd3-78c8-41cd-a476-38550d93a4a3">
384393
7. **Click OK**
385394

395+
## Migrating Modules
396+
397+
Sometimes you need to move or migrate an existing module from one project to another. This process involves copying the module files and updating the target project's configuration. The **Migrate** module in this project demonstrates how an external module can be integrated.
398+
399+
> **📝 Migration Note:**
400+
> Module migration is useful when you want to:
401+
> - Share modules between different projects
402+
> - Move modules from an experimental project to production
403+
> - Reuse existing functionality in new projects
404+
> - Backup and restore specific modules
405+
406+
### Step 1: Copy the Module Folder
407+
408+
The first step is to copy the entire module folder from the source project:
409+
410+
1. **Open File Explorer** and navigate to the source project's `Source/` directory
411+
2. **Locate the module** you want to migrate (in this case, it's the `Migrate` module)
412+
3. **Copy the entire module folder** including all subdirectories and files
413+
414+
```
415+
SourceProject/Source/
416+
└── Migrate/ # Copy this entire folder
417+
├── Migrate.Build.cs
418+
├── Public/
419+
│ ├── Migrate.h
420+
│ └── MigrateActor.h
421+
└── Private/
422+
├── Migrate.cpp
423+
└── MigrateActor.cpp
424+
```
425+
426+
### Step 2: Paste to Target Project
427+
428+
Paste the copied module folder to the target project:
429+
430+
1. **Navigate to the target project's `Source/` directory**
431+
2. **Paste the module folder** at the same hierarchy level as existing modules like `Auto` and `Manual`
432+
433+
```
434+
TargetProject/Source/
435+
├── Auto/ # Existing module
436+
├── Manual/ # Existing module
437+
├── Migrate/ # ✅ Newly migrated module
438+
│ ├── Migrate.Build.cs
439+
│ ├── Public/
440+
│ │ ├── Migrate.h
441+
│ │ └── MigrateActor.h
442+
│ └── Private/
443+
│ ├── Migrate.cpp
444+
│ └── MigrateActor.cpp
445+
└── FirstModule/ # Main game module
446+
```
447+
448+
### Step 3: Update Target Project Configuration
449+
450+
After copying the files, you need to register the migrated module in the target project:
451+
452+
#### Update .uproject File
453+
454+
Add the new module to `FirstModule.uproject`:
455+
456+
```json
457+
{
458+
"FileVersion": 3,
459+
"EngineAssociation": "5.6",
460+
"Modules": [
461+
{
462+
"Name": "FirstModule",
463+
"Type": "Runtime",
464+
"LoadingPhase": "Default"
465+
},
466+
{
467+
"Name": "Auto",
468+
"Type": "Runtime",
469+
"LoadingPhase": "Default"
470+
},
471+
{
472+
"Name": "Manual",
473+
"Type": "Runtime",
474+
"LoadingPhase": "Default"
475+
},
476+
{
477+
"Name": "Migrate", // ✅ Add this entry
478+
"Type": "Runtime",
479+
"LoadingPhase": "Default"
480+
}
481+
]
482+
}
483+
```
484+
485+
#### Update Target.cs Files
486+
487+
Add the module name to both `FirstModule.Target.cs` and `FirstModuleEditor.Target.cs`:
488+
489+
**FirstModule.Target.cs:**
490+
```csharp
491+
private void RegisterModulesCreatedByRider()
492+
{
493+
ExtraModuleNames.AddRange(["Auto", "Manual", "Migrate"]); // ✅ Add "Migrate"
494+
}
495+
```
496+
497+
**FirstModuleEditor.Target.cs:**
498+
```csharp
499+
private void RegisterModulesCreatedByRider()
500+
{
501+
ExtraModuleNames.AddRange(["Auto", "Manual", "Migrate"]); // ✅ Add "Migrate"
502+
}
503+
```
504+
505+
### Step 4: Regenerate Project Files
506+
507+
After updating the configuration files:
508+
509+
1. **Close your IDE** (Rider/Visual Studio)
510+
2. **Right-click on `FirstModule.uproject`** → Select "Generate Visual Studio Project Files"
511+
3. **Wait for generation to complete**
512+
4. **Reopen the project** in your IDE
513+
514+
### Step 5: Verify Migration
515+
516+
To confirm the migration was successful:
517+
518+
1. **Check that the module compiles** without errors
519+
2. **Verify module loading** in the UE Editor logs:
520+
```
521+
LogTemp: Warning: MigrateActor::AMigrateActor
522+
```
523+
3. **Test module functionality** by using its classes in other modules or Blueprints
524+
525+
### Migration Best Practices
526+
527+
#### ✅ Do:
528+
- **Keep module self-contained**: Ensure the module doesn't have hard-coded dependencies on the source project
529+
- **Update dependencies carefully**: Check if the target project has all required dependencies
530+
- **Test thoroughly**: Verify all functionality works in the new environment
531+
- **Maintain API consistency**: Keep public interfaces stable for easier migration
532+
533+
#### ❌ Don't:
534+
- **Copy system-specific files**: Don't migrate `Intermediate/` or `Binaries/` folders
535+
- **Ignore dependencies**: Make sure all required modules exist in the target project
536+
- **Skip regeneration**: Always regenerate project files after migration
537+
- **Assume compatibility**: Different UE versions might require code adjustments
538+
539+
### Common Migration Issues
540+
541+
#### Issue 1: Missing Dependencies
542+
**Symptoms**: Compilation errors about missing includes or undefined classes
543+
**Solution**: Ensure all dependency modules exist in the target project or update `Build.cs`
544+
545+
#### Issue 2: API Mismatch
546+
**Symptoms**: Linker errors or undefined symbols
547+
**Solution**: Verify the `MIGRATE_API` macro is correctly defined and used
548+
549+
#### Issue 3: Module Not Loading
550+
**Symptoms**: Module doesn't appear in the modules list
551+
**Solution**: Double-check `.uproject` and `Target.cs` entries, then regenerate project files
552+
553+
### Advanced Migration Scenarios
554+
555+
#### Cross-Version Migration
556+
When migrating between different UE versions:
557+
1. **Check API changes** in the UE documentation
558+
2. **Update deprecated functions** to their modern equivalents
559+
3. **Verify Build.cs compatibility** with the target UE version
560+
561+
#### Dependency Chain Migration
562+
When migrating a module that depends on other custom modules:
563+
1. **Migrate dependencies first** in the correct order
564+
2. **Update Build.cs dependencies** to match the target project structure
565+
3. **Test the entire dependency chain** after migration
566+
567+
Module migration is a powerful feature that enables code reuse across projects and helps maintain a modular architecture. The **Migrate** module in this project serves as a practical example of how external modules can be seamlessly integrated into existing projects.
568+
386569
## Module Dependencies
387570

388571
> **📝 Naming Convention Note:**

Source/FirstModule.Target.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public FirstModuleTarget(TargetInfo Target) : base(Target)
2020

2121
private void RegisterModulesCreatedByRider()
2222
{
23-
ExtraModuleNames.AddRange(["Auto", "Manual"]);
23+
ExtraModuleNames.AddRange(["Auto", "Manual", "Migrate"]);
2424
}
2525
}

Source/FirstModuleEditor.Target.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public FirstModuleEditorTarget(TargetInfo Target) : base(Target)
2020

2121
private void RegisterModulesCreatedByRider()
2222
{
23-
ExtraModuleNames.AddRange(["Auto"]);
23+
ExtraModuleNames.AddRange(["Auto", "Manual", "Migrate"]);
2424
}
2525
}

Source/Migrate/Migrate.Build.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using UnrealBuildTool;
2+
3+
public class Migrate : ModuleRules
4+
{
5+
public Migrate(ReadOnlyTargetRules Target) : base(Target)
6+
{
7+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
8+
9+
PublicDependencyModuleNames.AddRange(
10+
new string[]
11+
{
12+
"Core",
13+
}
14+
);
15+
16+
PrivateDependencyModuleNames.AddRange(
17+
new string[]
18+
{
19+
"CoreUObject",
20+
"Engine",
21+
"Slate",
22+
"SlateCore"
23+
}
24+
);
25+
}
26+
}

Source/Migrate/Private/Migrate.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "Migrate.h"
2+
3+
#define LOCTEXT_NAMESPACE "FMigrateModule"
4+
5+
void FMigrateModule::StartupModule()
6+
{
7+
8+
}
9+
10+
void FMigrateModule::ShutdownModule()
11+
{
12+
13+
}
14+
15+
#undef LOCTEXT_NAMESPACE
16+
17+
IMPLEMENT_MODULE(FMigrateModule, Migrate)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
4+
#include "MigrateActor.h"
5+
6+
7+
// Sets default values
8+
AMigrateActor::AMigrateActor()
9+
{
10+
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
11+
PrimaryActorTick.bCanEverTick = true;
12+
13+
UE_LOG(LogTemp, Warning, TEXT("MigrateActor::AMigrateActor"));
14+
}
15+
16+
// Called when the game starts or when spawned
17+
void AMigrateActor::BeginPlay()
18+
{
19+
Super::BeginPlay();
20+
}
21+
22+
// Called every frame
23+
void AMigrateActor::Tick(float DeltaTime)
24+
{
25+
Super::Tick(DeltaTime);
26+
}

Source/Migrate/Public/Migrate.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "CoreMinimal.h"
4+
#include "Modules/ModuleManager.h"
5+
6+
class FMigrateModule : public IModuleInterface
7+
{
8+
public:
9+
virtual void StartupModule() override;
10+
virtual void ShutdownModule() override;
11+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#pragma once
4+
5+
#include "CoreMinimal.h"
6+
#include "GameFramework/Actor.h"
7+
#include "MigrateActor.generated.h"
8+
9+
UCLASS()
10+
class MIGRATE_API AMigrateActor : public AActor
11+
{
12+
GENERATED_BODY()
13+
14+
public:
15+
// Sets default values for this actor's properties
16+
AMigrateActor();
17+
18+
protected:
19+
// Called when the game starts or when spawned
20+
virtual void BeginPlay() override;
21+
22+
public:
23+
// Called every frame
24+
virtual void Tick(float DeltaTime) override;
25+
};

0 commit comments

Comments
 (0)