代碼重構
開發程序中,需要對class、function、enum、variable改名,此處介紹如何處理,
一、可以明確物件被少量參考
- 父類修改:直接打開藍圖,然后在 Class Settings > Class Options > Parent Class,修改成新的類名
- 其它的函式、變數、列舉修改:找使用的地方直接改

二、物件被大量參考
主要流程如下:
A=>start: 打開檔案:DefaultEngine.ini
op_a=>operation: 添加:[CoreRedirects]
op_b=>operation: 配置好+ClassRedirects=
op_c=>operation: 重啟UnrealEditor
op_d=>operation: 觀察,可以看到參考已修改
e=>end: 完結
A->op_a->op_b->op_c->op_d->e
支持重定向class, struct, enum, function, member
1. 重定向類的方法
修改DefaultEngine.ini檔案
[CoreRedirects]
+ClassRedirects=(OldName="Pawn",NewName="MyPawn",InstanceOnly=true)
+ClassRedirects=(OldName="/Script/MyModule.MyOldClass",NewName="/Script/MyModule.MyNewClass")
+ClassRedirects=(OldName="PointLightComponent",NewName="PointLightComponent",ValueChanges=(("PointLightComponent0","LightComponent0")))
+ClassRedirects=(OldName="AnimNotify_PlayParticleEffect_C",NewName="/Script/Engine.AnimNotify_PlayParticleEffect",OverrideClassName="/Script/CoreUObject.Class")
欄位含義如下:
| 欄位名 | 型別 | 功能 |
|---|---|---|
| OldName | String | 類的舊名字 |
| NewName | String | 類的新名字 |
| MatchSubstring | Bool | (可選)任意名字匹配到,都替換 |
| OverrideClassName | String | (可選)指定要對UCLASS的底層類進行的更改,此欄位通常用于將藍圖類更改為原生類(/Script/CoreUObject.Class), |
| InstanceOnly | Bool | (可選)只對實體生成 |
| ValueChanges | List of String pairs | (可選)重命名OldName對應的實體,每一對pair的第一個是實體名字,第二個是新名字 |
獲得類名的方法:

組態檔寫好后,保存,并重啟UnrealEditor,順序的話,可以看到實體化物件的Parent Class都變成新的class了,
2.重定向Enum、Struct,與重定向類差不多
Enum的欄位與Class類似,見類欄位
[CoreRedirects]
+EnumRedirects=(OldName="ENumbers",NewName="ELetters",ValueChanges=(("NumberTwo","LetterB"),("NumberThree","LetterC")))
3.重定向Function
[CoreRedirects]
+FunctionRedirects=(OldName="MyOldActor.OldFunction",NewName="MyNewActor.NewFunction")
+FunctionRedirects=(OldName="MyActor.OldFunction",NewName="NewFunction")
| Field | Type | Purpose |
|---|---|---|
| OldName | String | 函式的舊名字 |
| NewName | String | 函式的新名字 |
| MatchSubstring | Bool | (可選)任意名字匹配到,都替換 |
4. 重定向Package
[CoreRedirects]
+PackageRedirects=(OldName="OldPlugin",NewName="/NewPlugin/",MatchSubstring=true)
+PackageRedirects=(OldName="/Game/DeletedContentPackage",Removed=true)
| Field | Type | Purpose |
|---|---|---|
| OldName | String | Specifies the name of the obsolete or deleted package. |
| NewName | String | (Optional) If remapping is desired, this specifies the name of the package that replaces the obsolete or deleted package. If this is not present, Removed should be present and set to true. |
| MatchSubstring | Bool | (Optional) If present and set to true, this Core Redirect will apply to any package containing the value of OldName, rather than requiring an exact match. |
| Removed | Bool | (Optional) If present and set to true, the named package has been removed. References to any of the removed content will be set to null without generating warnings or errors. The NewName argument should not be present if this is the case. |
5. 重定向屬性
[CoreRedirects]
+PropertyRedirects=(OldName="MyOldActor.OldIntProperty",NewName="MyNewActor.NewIntProperty")
+PropertyRedirects=(OldName="MyActor.OldFloatProperty",NewName="NewFloatProperty")
| Field | Type | Purpose |
|---|---|---|
| OldName | String | 舊屬性名,示例:"類名.屬性名", MyActor.MyStruct.MyProperty. |
| NewName | String | 新屬性名,示例:"類名.屬性名", MyActor.MyStruct.MyProperty. |
| MatchSubstring | Bool | (可選)任意名字匹配到,都替換 |
參考資料:
UE5 Core Redirects
友情鏈接:
blog: https://www.cgsgood.tech/ue_code_refactor
語雀: https://www.yuque.com/cgsgood/dshx0b/qhqlmldu7s28o9bd
博客園: https://www.cnblogs.com/cgsgood/p/16876703.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/531478.html
標籤:其他
上一篇:解密負載均衡技術和負載均衡演算法
