ue-mcp 1.4.13 → 1.4.14-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/README.md +5 -5
  2. package/dist/bridge/bridge-timeouts.js +4 -0
  3. package/dist/bridge/bridge-timeouts.js.map +1 -1
  4. package/dist/cli/cli-commands.js +1 -0
  5. package/dist/cli/cli-commands.js.map +1 -1
  6. package/dist/cli/doctor.js +2 -1
  7. package/dist/cli/doctor.js.map +1 -1
  8. package/dist/cli/init.js +1 -1
  9. package/dist/cli/init.js.map +1 -1
  10. package/dist/cli/projects-cli.d.ts +3 -0
  11. package/dist/cli/projects-cli.js +72 -0
  12. package/dist/cli/projects-cli.js.map +1 -0
  13. package/dist/config/user-state.d.ts +10 -0
  14. package/dist/config/user-state.js +21 -0
  15. package/dist/config/user-state.js.map +1 -1
  16. package/dist/core/env.d.ts +2 -0
  17. package/dist/core/env.js +2 -0
  18. package/dist/core/env.js.map +1 -1
  19. package/dist/core/types.d.ts +27 -0
  20. package/dist/daemon/daemon.js +44 -5
  21. package/dist/daemon/daemon.js.map +1 -1
  22. package/dist/daemon/extension-api.d.ts +8 -5
  23. package/dist/daemon-api.d.ts +2 -1
  24. package/dist/daemon-api.js +1 -0
  25. package/dist/daemon-api.js.map +1 -1
  26. package/dist/dispatch/offline.js +1 -0
  27. package/dist/dispatch/offline.js.map +1 -1
  28. package/dist/editor/dialog-guard.d.ts +12 -2
  29. package/dist/editor/dialog-guard.js +68 -2
  30. package/dist/editor/dialog-guard.js.map +1 -1
  31. package/dist/editor/editor-control.js +1 -1
  32. package/dist/editor/editor-control.js.map +1 -1
  33. package/dist/flow/write-methods.js +1 -1
  34. package/dist/flow/write-methods.js.map +1 -1
  35. package/dist/machine/projects.d.ts +85 -0
  36. package/dist/machine/projects.js +286 -0
  37. package/dist/machine/projects.js.map +1 -0
  38. package/dist/pie/script-events.d.ts +4 -1
  39. package/dist/pie/script-events.js.map +1 -1
  40. package/dist/surface/context/instructions.js +20 -0
  41. package/dist/surface/context/instructions.js.map +1 -1
  42. package/dist/tool-counts.json +12 -12
  43. package/dist/tools/asset.js +2 -1
  44. package/dist/tools/asset.js.map +1 -1
  45. package/dist/tools/editor.js +1 -1
  46. package/dist/tools/editor.js.map +1 -1
  47. package/dist/tools/epic/effects.js +11 -0
  48. package/dist/tools/epic/effects.js.map +1 -1
  49. package/dist/tools/epic/fab.generated.d.ts +6 -0
  50. package/dist/tools/epic/fab.generated.js +67 -0
  51. package/dist/tools/epic/fab.generated.js.map +1 -0
  52. package/dist/tools/epic/index.d.ts +2 -0
  53. package/dist/tools/epic/index.js +2 -0
  54. package/dist/tools/epic/index.js.map +1 -1
  55. package/dist/tools/epic/toolset-routes.js +2 -0
  56. package/dist/tools/epic/toolset-routes.js.map +1 -1
  57. package/dist/tools/epic.js +4 -4
  58. package/dist/tools/epic.js.map +1 -1
  59. package/dist/tools/fab-epic.d.ts +23 -0
  60. package/dist/tools/fab-epic.js +109 -0
  61. package/dist/tools/fab-epic.js.map +1 -0
  62. package/dist/tools/fab.js +27 -18
  63. package/dist/tools/fab.js.map +1 -1
  64. package/dist/tools/level.js +9 -2
  65. package/dist/tools/level.js.map +1 -1
  66. package/dist/tools/material.js +1 -1
  67. package/dist/tools/material.js.map +1 -1
  68. package/dist/tools/pie.js +1 -1
  69. package/dist/tools/pie.js.map +1 -1
  70. package/dist/tools/specs/asset.generated.js +92 -3
  71. package/dist/tools/specs/asset.generated.js.map +1 -1
  72. package/dist/tools/specs/fab.generated.js +143 -3
  73. package/dist/tools/specs/fab.generated.js.map +1 -1
  74. package/dist/tools/specs/level.generated.js +183 -9
  75. package/dist/tools/specs/level.generated.js.map +1 -1
  76. package/dist/tools/specs/pie.generated.js +28 -8
  77. package/dist/tools/specs/pie.generated.js.map +1 -1
  78. package/dist/tools/specs/widget.generated.js +8 -1
  79. package/dist/tools/specs/widget.generated.js.map +1 -1
  80. package/dist/ue-mcp.default.yml +522 -76
  81. package/package.json +2 -2
  82. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/BridgeServer.cpp +26 -0
  83. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.cpp +24 -0
  84. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers.h +7 -0
  85. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Asset/AssetHandlers_Mesh.cpp +483 -10
  86. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Dialog/DialogHandlers.cpp +345 -1
  87. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Epic/EpicHandlers_AIAssistant.cpp +34 -6
  88. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabDownloads.cpp +766 -0
  89. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabDownloads.h +26 -0
  90. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabHandlers.cpp +159 -55
  91. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabHandlers.h +23 -12
  92. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabLibrary.cpp +306 -0
  93. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Fab/FabLibrary.h +55 -0
  94. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.cpp +34 -2
  95. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers.h +9 -0
  96. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Blockout.cpp +12 -8
  97. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_PerfAudit.cpp +3 -1
  98. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_Refresh.cpp +479 -0
  99. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_ReplaceActors.cpp +2 -0
  100. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Level/LevelHandlers_WorldPartition.cpp +824 -12
  101. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Material/MaterialHandlers.cpp +95 -1
  102. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PCG/PCGHandlers.cpp +13 -0
  103. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/MCPPIETestScript.h +8 -3
  104. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers.cpp +2 -0
  105. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Record.cpp +6 -0
  106. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Replay.cpp +1 -0
  107. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEHandlers_Script.cpp +2 -2
  108. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputRecorder.cpp +52 -1
  109. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputRecorder.h +16 -0
  110. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputReplayer.cpp +65 -1
  111. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEInputReplayer.h +15 -0
  112. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEReplayInputLock.cpp +146 -0
  113. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEReplayInputLock.h +53 -0
  114. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptRunner.cpp +351 -14
  115. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptRunner.h +55 -6
  116. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEScriptValidation.cpp +8 -1
  117. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIESequenceFormat.cpp +59 -0
  118. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIESequenceFormat.h +15 -2
  119. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEUIPointer.cpp +567 -0
  120. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/PIEUIPointer.h +173 -0
  121. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/PIE/SMCPPIEStudioPanel.cpp +41 -6
  122. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Handlers/Widget/WidgetHandlers.cpp +92 -32
  123. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabDownloadTests.cpp +140 -0
  124. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabEndToEndTests.cpp +365 -0
  125. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/FabLibraryTests.cpp +52 -0
  126. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PCGGraphAuthoringTests.cpp +5 -2
  127. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEReplayInputLockTests.cpp +77 -0
  128. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEScriptTests.cpp +256 -0
  129. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEScriptValidationTests.cpp +18 -0
  130. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/Tests/PIEUIPointerTests.cpp +246 -0
  131. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/Private/UE_MCP_Bridge.cpp +4 -0
  132. package/plugin/ue_mcp_bridge/Source/UE_MCP_Bridge/UE_MCP_Bridge.Build.cs +85 -13
  133. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Private/MCPPIEActionTrigger.cpp +48 -0
  134. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Private/MCPPIERemoteControl.cpp +93 -0
  135. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Public/MCPPIEActionTrigger.h +52 -0
  136. package/plugin/ue_mcp_bridge/Source/UE_MCP_BridgeRuntime/Public/MCPPIERemoteControl.h +54 -0
  137. package/plugin/ue_mcp_bridge/UE_MCP_Bridge.uplugin +2 -2
@@ -17,22 +17,31 @@
17
17
  // its scaled bounds, and there was no way to ask whether two
18
18
  // components actually overlap without a physics query that depends on
19
19
  // the collision state #915 is about.
20
+ // resave_mesh_users A SplineMeshComponent saves its own copy of its mesh's
21
+ // collision with the actor, and an edit to the mesh that left its
22
+ // BodySetupGuid alone left every copy stale in memory and on disk.
20
23
 
21
24
  #include "LevelHandlers.h"
25
+ #include "Handlers/Asset/AssetHandlers.h"
22
26
 
23
27
  #include "Components/ActorComponent.h"
24
28
  #include "Components/BoxComponent.h"
25
29
  #include "Components/PrimitiveComponent.h"
26
30
  #include "Components/SceneComponent.h"
31
+ #include "Components/SplineMeshComponent.h"
32
+ #include "Components/StaticMeshComponent.h"
27
33
  #include "Dom/JsonObject.h"
28
34
  #include "Dom/JsonValue.h"
29
35
  #include "Editor.h"
30
36
  #include "Engine/EngineTypes.h"
37
+ #include "Engine/StaticMesh.h"
31
38
  #include "Engine/World.h"
32
39
  #include "EngineUtils.h"
33
40
  #include "GameFramework/Actor.h"
41
+ #include "HAL/FileManager.h"
34
42
  #include "HandlerRegistry.h"
35
43
  #include "HandlerUtils.h"
44
+ #include "PhysicsEngine/BodySetup.h"
36
45
  #include "UObject/Package.h"
37
46
  #include "UObject/UObjectHash.h"
38
47
 
@@ -273,6 +282,80 @@ namespace
273
282
  }
274
283
  return Object;
275
284
  }
285
+
286
+ FString MCPMeshUsersGuidString(const FGuid& Guid)
287
+ {
288
+ return Guid.ToString(EGuidFormats::DigitsWithHyphens);
289
+ }
290
+
291
+ /** The mesh GUID a SplineMeshComponent last rebuilt its collision copy from. Read through reflection: it is a
292
+ * saved UPROPERTY, and what this action has to report is the value that will be written. */
293
+ FGuid MCPMeshUsersCachedGuid(const USplineMeshComponent* Spline)
294
+ {
295
+ static const FName CachedGuidName(TEXT("CachedMeshBodySetupGuid"));
296
+ const FStructProperty* Property = FindFProperty<FStructProperty>(USplineMeshComponent::StaticClass(), CachedGuidName);
297
+ if (!Spline || !Property || Property->Struct != TBaseStructure<FGuid>::Get()) return FGuid();
298
+ return *Property->ContainerPtrToValuePtr<FGuid>(Spline);
299
+ }
300
+
301
+ /** The collision a component is using now: its body setup's GUID and the bounds of its simple shapes in the
302
+ * component's own space. A SplineMeshComponent's body setup is its own deformed copy, not the mesh's. */
303
+ TSharedPtr<FJsonObject> MCPMeshUsersCollisionState(UStaticMeshComponent* Component)
304
+ {
305
+ TSharedPtr<FJsonObject> State = MakeShared<FJsonObject>();
306
+ State->SetStringField(TEXT("collisionEnabled"), MCPRefreshCollisionName(Component->GetCollisionEnabled()));
307
+ State->SetBoolField(TEXT("physicsStateCreated"), Component->IsPhysicsStateCreated());
308
+ UBodySetup* Setup = Component->GetBodySetup();
309
+ State->SetBoolField(TEXT("hasBodySetup"), Setup != nullptr);
310
+ if (Setup)
311
+ {
312
+ State->SetStringField(TEXT("bodySetupGuid"), MCPMeshUsersGuidString(Setup->BodySetupGuid));
313
+ State->SetNumberField(TEXT("shapeCount"), Setup->AggGeom.GetElementCount());
314
+ if (Setup->AggGeom.GetElementCount() > 0)
315
+ {
316
+ const FBox Box = Setup->AggGeom.CalcAABB(FTransform::Identity);
317
+ TSharedPtr<FJsonObject> Bounds = MakeShared<FJsonObject>();
318
+ Bounds->SetObjectField(TEXT("min"), MCPVec3ToJsonObject(Box.Min));
319
+ Bounds->SetObjectField(TEXT("max"), MCPVec3ToJsonObject(Box.Max));
320
+ Bounds->SetObjectField(TEXT("size"), MCPVec3ToJsonObject(Box.GetSize()));
321
+ State->SetObjectField(TEXT("bodySetupBounds"), Bounds);
322
+ }
323
+ }
324
+ if (const USplineMeshComponent* Spline = Cast<USplineMeshComponent>(Component))
325
+ {
326
+ UStaticMesh* Mesh = Spline->GetStaticMesh();
327
+ const UBodySetup* MeshSetup = Mesh ? Mesh->GetBodySetup() : nullptr;
328
+ const FGuid Cached = MCPMeshUsersCachedGuid(Spline);
329
+ State->SetStringField(TEXT("cachedMeshBodySetupGuid"), MCPMeshUsersGuidString(Cached));
330
+ State->SetBoolField(TEXT("copyMatchesMeshGuid"), MeshSetup && Cached == MeshSetup->BodySetupGuid);
331
+ }
332
+ return State;
333
+ }
334
+
335
+ /** A package's file as it is on disk right now, so a save can be judged by what changed rather than by its
336
+ * return value. Modification times are whole seconds, so a same-size rewrite within one second reads as no
337
+ * change; the save status is the other half of the answer. */
338
+ struct FMCPMeshUsersFileState
339
+ {
340
+ FString File;
341
+ bool bExists = false;
342
+ int64 Size = -1;
343
+ FDateTime Stamp = FDateTime::MinValue();
344
+ };
345
+
346
+ FMCPMeshUsersFileState MCPMeshUsersReadFile(UPackage* Package)
347
+ {
348
+ FMCPMeshUsersFileState State;
349
+ if (!ResolvePackageFileName(Package, State.File)) return State;
350
+ IFileManager& FileManager = IFileManager::Get();
351
+ State.bExists = FileManager.FileExists(*State.File);
352
+ if (State.bExists)
353
+ {
354
+ State.Size = FileManager.FileSize(*State.File);
355
+ State.Stamp = FileManager.GetTimeStamp(*State.File);
356
+ }
357
+ return State;
358
+ }
276
359
  }
277
360
 
278
361
  // ---------------------------------------------------------------------------
@@ -713,6 +796,402 @@ TSharedPtr<FJsonValue> FLevelHandlers::RecreatePhysicsState(const TSharedPtr<FJs
713
796
  return MCPResult(Result);
714
797
  }
715
798
 
799
+ // ---------------------------------------------------------------------------
800
+ // resave_mesh_users
801
+ //
802
+ // A SplineMeshComponent keeps its own deformed copy of its mesh's body setup,
803
+ // saved with the actor, and rebuilds it in OnCreatePhysicsState only when the
804
+ // mesh's BodySetupGuid differs from the GUID it cached. A collision edit that
805
+ // left the GUID alone (an AggGeom write through Python) leaves every copy
806
+ // stale, and a rebuild in memory still leaves the saved actor packages holding
807
+ // the old one. This rebuilds the copies from the current mesh and saves exactly
808
+ // the packages that own those actors, through asset(save, assetPaths)'s
809
+ // targeted save, so no other dirty package in the session is written.
810
+ // ---------------------------------------------------------------------------
811
+ TSharedPtr<FJsonValue> FLevelHandlers::ResaveMeshUsers(const TSharedPtr<FJsonObject>& Params)
812
+ {
813
+ MCP_CHECK_GAME_THREAD();
814
+ MCPReadParamsAhead(Params, {
815
+ TEXT("meshPaths"), TEXT("componentClass"), TEXT("recreateCollision"), TEXT("save"), TEXT("dryRun"), TEXT("maxActors"),
816
+ });
817
+
818
+ TArray<FString> MeshPaths;
819
+ {
820
+ const TArray<TSharedPtr<FJsonValue>>* MeshValues = nullptr;
821
+ if (TryGetArrayParam(Params, TEXT("meshPaths"), MeshValues) && MeshValues)
822
+ {
823
+ MeshPaths = JsonArrayToStringList(MeshValues);
824
+ }
825
+ }
826
+ const FString ComponentClassSpec = OptionalString(Params, TEXT("componentClass"), TEXT("any")).TrimStartAndEnd();
827
+ const bool bRecreate = OptionalBool(Params, TEXT("recreateCollision"), true);
828
+ const bool bSave = OptionalBool(Params, TEXT("save"), true);
829
+ // dryRun defaults to TRUE, as recreate_physics_state's does: which actors
830
+ // and packages this would rebuild and write is the preflight.
831
+ const bool bDryRun = OptionalBool(Params, TEXT("dryRun"), true);
832
+ const int32 MaxActors = FMath::Clamp(OptionalInt(Params, TEXT("maxActors"), 256), 1, MCPRefreshMaxActors);
833
+
834
+ constexpr int32 MaxMeshPaths = 256;
835
+ if (MeshPaths.IsEmpty())
836
+ {
837
+ return MCPError(TEXT("'meshPaths' must be a non-empty array of StaticMesh asset paths. Nothing was rebuilt or saved."));
838
+ }
839
+ if (MeshPaths.Num() > MaxMeshPaths)
840
+ {
841
+ return MCPError(FString::Printf(TEXT("%d meshPaths is over the limit of %d. Nothing was rebuilt or saved."), MeshPaths.Num(), MaxMeshPaths));
842
+ }
843
+
844
+ enum class EMCPMeshUserClass : uint8 { Any, StaticMesh, SplineMesh };
845
+ EMCPMeshUserClass ClassMode;
846
+ if (ComponentClassSpec.Equals(TEXT("any"), ESearchCase::IgnoreCase)) ClassMode = EMCPMeshUserClass::Any;
847
+ else if (ComponentClassSpec.Equals(TEXT("StaticMeshComponent"), ESearchCase::IgnoreCase)) ClassMode = EMCPMeshUserClass::StaticMesh;
848
+ else if (ComponentClassSpec.Equals(TEXT("SplineMeshComponent"), ESearchCase::IgnoreCase)) ClassMode = EMCPMeshUserClass::SplineMesh;
849
+ else
850
+ {
851
+ return MCPError(FString::Printf(
852
+ TEXT("Unknown componentClass '%s'. Use any, StaticMeshComponent or SplineMeshComponent. Nothing was rebuilt or saved."),
853
+ *ComponentClassSpec));
854
+ }
855
+
856
+ // Saving during PIE is refused by the editor for maps and races the play
857
+ // world for everything else, and a rebuild there would reach PIE copies.
858
+ if (GEditor && (GEditor->PlayWorld != nullptr || GEditor->bIsSimulatingInEditor))
859
+ {
860
+ TSharedPtr<FJsonObject> Refused = MCPErrorObject(
861
+ TEXT("Play In Editor is running. Stop it with editor(action=\"play_in_editor\", pieAction=\"stop\"), then run this again. Nothing was rebuilt or saved."));
862
+ Refused->SetStringField(TEXT("reason"), TEXT("play_in_editor_active"));
863
+ return MakeShared<FJsonValueObject>(Refused);
864
+ }
865
+
866
+ REQUIRE_EDITOR_WORLD(World);
867
+
868
+ // Every mesh resolves before anything is touched, so a typo refuses the call
869
+ // rather than quietly matching nothing.
870
+ TSet<FString> WantedMeshPaths;
871
+ TArray<TSharedPtr<FJsonValue>> MeshRows;
872
+ TArray<FString> Unresolved;
873
+ for (const FString& Path : MeshPaths)
874
+ {
875
+ UObject* Found = MCPLoadAssetObject(Path);
876
+ UStaticMesh* Mesh = Cast<UStaticMesh>(Found);
877
+ if (!Mesh)
878
+ {
879
+ Unresolved.Add(Found
880
+ ? FString::Printf(TEXT("%s (a %s, not a StaticMesh)"), *Path, *Found->GetClass()->GetName())
881
+ : FString::Printf(TEXT("%s (not found)"), *Path));
882
+ continue;
883
+ }
884
+ WantedMeshPaths.Add(Mesh->GetPathName().ToLower());
885
+ TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>();
886
+ Row->SetStringField(TEXT("requested"), Path);
887
+ Row->SetStringField(TEXT("objectPath"), Mesh->GetPathName());
888
+ if (const UBodySetup* MeshSetup = Mesh->GetBodySetup())
889
+ {
890
+ Row->SetStringField(TEXT("bodySetupGuid"), MCPMeshUsersGuidString(MeshSetup->BodySetupGuid));
891
+ }
892
+ MeshRows.Add(MakeShared<FJsonValueObject>(Row));
893
+ }
894
+ if (!Unresolved.IsEmpty())
895
+ {
896
+ TSharedPtr<FJsonObject> Refused = MCPErrorObject(FString::Printf(
897
+ TEXT("%d of %d meshPaths did not resolve to a StaticMesh, so nothing was rebuilt or saved. The first: %s"),
898
+ Unresolved.Num(), MeshPaths.Num(), *Unresolved[0]));
899
+ Refused->SetArrayField(TEXT("unresolved"), MCPStringListToJson(Unresolved));
900
+ return MakeShared<FJsonValueObject>(Refused);
901
+ }
902
+
903
+ struct FMCPMeshUser
904
+ {
905
+ AActor* Actor = nullptr;
906
+ TArray<UStaticMeshComponent*> Components;
907
+ };
908
+ TArray<FMCPMeshUser> Users;
909
+ int32 MatchedComponents = 0;
910
+ int32 MatchedSplines = 0;
911
+ for (TActorIterator<AActor> It(World); It; ++It)
912
+ {
913
+ AActor* Actor = *It;
914
+ if (!IsValid(Actor)) continue;
915
+ FMCPMeshUser User;
916
+ User.Actor = Actor;
917
+ TInlineComponentArray<UStaticMeshComponent*> Components(Actor);
918
+ for (UStaticMeshComponent* Component : Components)
919
+ {
920
+ if (!IsValid(Component)) continue;
921
+ const bool bSpline = Component->IsA<USplineMeshComponent>();
922
+ if (ClassMode == EMCPMeshUserClass::StaticMesh && bSpline) continue;
923
+ if (ClassMode == EMCPMeshUserClass::SplineMesh && !bSpline) continue;
924
+ const UStaticMesh* Mesh = Component->GetStaticMesh();
925
+ if (!Mesh || !WantedMeshPaths.Contains(Mesh->GetPathName().ToLower())) continue;
926
+ User.Components.Add(Component);
927
+ if (bSpline) ++MatchedSplines;
928
+ }
929
+ if (User.Components.Num() > 0)
930
+ {
931
+ MatchedComponents += User.Components.Num();
932
+ Users.Add(MoveTemp(User));
933
+ }
934
+ }
935
+ Users.Sort([](const FMCPMeshUser& A, const FMCPMeshUser& B) { return A.Actor->GetPathName() < B.Actor->GetPathName(); });
936
+
937
+ auto Result = MCPSuccess();
938
+ Result->SetBoolField(TEXT("dryRun"), bDryRun);
939
+ Result->SetStringField(TEXT("componentClass"), ComponentClassSpec);
940
+ Result->SetBoolField(TEXT("recreateCollision"), bRecreate);
941
+ Result->SetBoolField(TEXT("save"), bSave);
942
+ Result->SetArrayField(TEXT("meshes"), MeshRows);
943
+ Result->SetNumberField(TEXT("matchedActors"), Users.Num());
944
+ Result->SetNumberField(TEXT("matchedComponents"), MatchedComponents);
945
+ Result->SetNumberField(TEXT("matchedSplineMeshComponents"), MatchedSplines);
946
+ const bool bPartitioned = World->IsPartitionedWorld();
947
+ Result->SetBoolField(TEXT("worldPartition"), bPartitioned);
948
+ Result->SetStringField(TEXT("scope"), TEXT("loaded"));
949
+ Result->SetStringField(TEXT("scopeNote"), bPartitioned
950
+ ? TEXT("World Partition: only actors resident in the editor world were scanned. Actors in unloaded cells are not seen, rebuilt or saved. Load them first with level(load_actor_descs), then run this again.")
951
+ : TEXT("Only actors in levels loaded into the editor world were scanned. An unloaded streaming level's actors are not seen, rebuilt or saved."));
952
+
953
+ if (Users.Num() > MaxActors)
954
+ {
955
+ Result->SetBoolField(TEXT("success"), false);
956
+ Result->SetStringField(TEXT("error"), FString::Printf(
957
+ TEXT("Matched %d actors, over maxActors (%d). Nothing was rebuilt or saved. Narrow meshPaths or componentClass, or raise maxActors deliberately."),
958
+ Users.Num(), MaxActors));
959
+ return MCPResult(Result);
960
+ }
961
+
962
+ // One entry per package: the actor's external package under one file per
963
+ // actor, the level's own package otherwise, where every matched actor of
964
+ // that level shares one save.
965
+ TArray<UPackage*> PackageOrder;
966
+ TMap<UPackage*, TArray<int32>> UsersByPackage;
967
+ TMap<UPackage*, bool> DirtyBefore;
968
+ for (int32 Index = 0; Index < Users.Num(); ++Index)
969
+ {
970
+ UPackage* Package = Users[Index].Actor->GetPackage();
971
+ if (!Package) continue;
972
+ if (!UsersByPackage.Contains(Package))
973
+ {
974
+ PackageOrder.Add(Package);
975
+ DirtyBefore.Add(Package, Package->IsDirty());
976
+ }
977
+ UsersByPackage.FindOrAdd(Package).Add(Index);
978
+ }
979
+
980
+ // Component state before anything is rebuilt, so a caller can see a stale
981
+ // spline copy in the preflight and compare it with the result.
982
+ TMap<UStaticMeshComponent*, TSharedPtr<FJsonObject>> StateBefore;
983
+ for (const FMCPMeshUser& User : Users)
984
+ {
985
+ for (UStaticMeshComponent* Component : User.Components)
986
+ {
987
+ StateBefore.Add(Component, MCPMeshUsersCollisionState(Component));
988
+ }
989
+ }
990
+
991
+ int32 Recreated = 0;
992
+ int32 SplineCopiesRebuilt = 0;
993
+ if (!bDryRun)
994
+ {
995
+ for (const FMCPMeshUser& User : Users)
996
+ {
997
+ for (UStaticMeshComponent* Component : User.Components)
998
+ {
999
+ if (USplineMeshComponent* Spline = Cast<USplineMeshComponent>(Component))
1000
+ {
1001
+ // The copy and its cached GUID are saved with the actor, so its
1002
+ // package must be dirty for the save below to write them.
1003
+ if (bRecreate || bSave)
1004
+ {
1005
+ Spline->Modify();
1006
+ Spline->MarkPackageDirty();
1007
+ }
1008
+ if (bRecreate)
1009
+ {
1010
+ // Rebuilt from the mesh as it is now, whatever the GUID says.
1011
+ Spline->RecreateCollision();
1012
+ ++SplineCopiesRebuilt;
1013
+ }
1014
+ }
1015
+ if (bRecreate)
1016
+ {
1017
+ Component->RecreatePhysicsState();
1018
+ ++Recreated;
1019
+ }
1020
+ }
1021
+ }
1022
+ }
1023
+
1024
+ TArray<TSharedPtr<FJsonValue>> PackageRows;
1025
+ int32 SavedCount = 0;
1026
+ int32 NotDirtyCount = 0;
1027
+ int32 FailedCount = 0;
1028
+ int32 FileChangedCount = 0;
1029
+ int32 ComponentRows = 0;
1030
+ FString FirstFailure;
1031
+ for (UPackage* Package : PackageOrder)
1032
+ {
1033
+ TSharedPtr<FJsonObject> Row = MakeShared<FJsonObject>();
1034
+ const TArray<int32>& PackageUsers = UsersByPackage.FindChecked(Package);
1035
+ Row->SetStringField(TEXT("package"), Package->GetName());
1036
+ Row->SetBoolField(TEXT("external"), Users[PackageUsers[0]].Actor->IsPackageExternal());
1037
+ Row->SetBoolField(TEXT("isMap"), IsMapPackage(Package));
1038
+ Row->SetBoolField(TEXT("wasDirty"), DirtyBefore.FindRef(Package));
1039
+
1040
+ int32 PackageComponents = 0;
1041
+ bool bPackageHasSpline = false;
1042
+ TArray<TSharedPtr<FJsonValue>> ActorRows;
1043
+ for (const int32 Index : PackageUsers)
1044
+ {
1045
+ const FMCPMeshUser& User = Users[Index];
1046
+ for (UStaticMeshComponent* Component : User.Components)
1047
+ {
1048
+ bPackageHasSpline |= Component->IsA<USplineMeshComponent>();
1049
+ }
1050
+ TSharedPtr<FJsonObject> ActorRow = MakeShared<FJsonObject>();
1051
+ ActorRow->SetStringField(TEXT("actorLabel"), User.Actor->GetActorLabel());
1052
+ ActorRow->SetStringField(TEXT("actorPath"), User.Actor->GetPathName());
1053
+ ActorRow->SetNumberField(TEXT("componentCount"), User.Components.Num());
1054
+ TArray<TSharedPtr<FJsonValue>> ComponentValues;
1055
+ for (UStaticMeshComponent* Component : User.Components)
1056
+ {
1057
+ ++PackageComponents;
1058
+ if (ComponentRows >= MCPRefreshMaxResultRows) continue;
1059
+ ++ComponentRows;
1060
+ TSharedPtr<FJsonObject> ComponentRow = MakeShared<FJsonObject>();
1061
+ ComponentRow->SetStringField(TEXT("componentName"), Component->GetName());
1062
+ ComponentRow->SetStringField(TEXT("componentClass"), Component->GetClass()->GetName());
1063
+ ComponentRow->SetStringField(TEXT("meshPath"), Component->GetStaticMesh() ? Component->GetStaticMesh()->GetPathName() : FString());
1064
+ ComponentRow->SetStringField(TEXT("status"), bDryRun
1065
+ ? (bRecreate ? TEXT("would_recreate") : TEXT("would_keep"))
1066
+ : (bRecreate ? TEXT("recreated") : TEXT("kept")));
1067
+ ComponentRow->SetObjectField(TEXT("before"), StateBefore.FindRef(Component));
1068
+ if (!bDryRun) ComponentRow->SetObjectField(TEXT("after"), MCPMeshUsersCollisionState(Component));
1069
+ ComponentValues.Add(MakeShared<FJsonValueObject>(ComponentRow));
1070
+ }
1071
+ ActorRow->SetArrayField(TEXT("components"), ComponentValues);
1072
+ ActorRows.Add(MakeShared<FJsonValueObject>(ActorRow));
1073
+ }
1074
+ Row->SetNumberField(TEXT("componentCount"), PackageComponents);
1075
+ Row->SetArrayField(TEXT("actors"), ActorRows);
1076
+
1077
+ const FMCPMeshUsersFileState Before = MCPMeshUsersReadFile(Package);
1078
+ Row->SetStringField(TEXT("file"), Before.File);
1079
+ Row->SetBoolField(TEXT("existedOnDisk"), Before.bExists);
1080
+ Row->SetNumberField(TEXT("fileSizeBefore"), static_cast<double>(Before.Size));
1081
+ if (Before.bExists) Row->SetStringField(TEXT("modifiedUtcBefore"), Before.Stamp.ToIso8601());
1082
+
1083
+ if (bDryRun || !bSave)
1084
+ {
1085
+ // A real run dirties a package only through a spline copy it saves.
1086
+ const TCHAR* Planned = bPackageHasSpline || DirtyBefore.FindRef(Package) ? TEXT("wouldSave") : TEXT("wouldBeNotDirty");
1087
+ Row->SetStringField(TEXT("status"), bDryRun && bSave ? Planned : TEXT("notSaved"));
1088
+ Row->SetBoolField(TEXT("dirtyNow"), Package->IsDirty());
1089
+ PackageRows.Add(MakeShared<FJsonValueObject>(Row));
1090
+ continue;
1091
+ }
1092
+
1093
+ // The same targeted save asset(save, assetPaths) runs, one package per
1094
+ // call so one read-only file does not stop the others being written.
1095
+ TArray<TSharedPtr<FJsonValue>> One;
1096
+ One.Add(MakeShared<FJsonValueString>(Package->GetName()));
1097
+ const TSharedPtr<FJsonValue> SaveValue = FAssetHandlers::SaveNamedPackages(One);
1098
+ const TSharedPtr<FJsonObject> Saved = SaveValue.IsValid() ? SaveValue->AsObject() : nullptr;
1099
+ FString Status = TEXT("failed");
1100
+ FString Reason = TEXT("the targeted save returned no result");
1101
+ if (Saved.IsValid())
1102
+ {
1103
+ const TArray<TSharedPtr<FJsonValue>>* Rows = nullptr;
1104
+ const TArray<TSharedPtr<FJsonValue>>* RefusedRows = nullptr;
1105
+ if (Saved->TryGetArrayField(TEXT("results"), Rows) && Rows && Rows->Num() > 0 && (*Rows)[0]->AsObject().IsValid())
1106
+ {
1107
+ const TSharedPtr<FJsonObject> First = (*Rows)[0]->AsObject();
1108
+ First->TryGetStringField(TEXT("status"), Status);
1109
+ Reason.Reset();
1110
+ First->TryGetStringField(TEXT("reason"), Reason);
1111
+ }
1112
+ else if (Saved->TryGetArrayField(TEXT("refused"), RefusedRows) && RefusedRows && RefusedRows->Num() > 0 && (*RefusedRows)[0]->AsObject().IsValid())
1113
+ {
1114
+ Reason.Reset();
1115
+ (*RefusedRows)[0]->AsObject()->TryGetStringField(TEXT("reason"), Reason);
1116
+ }
1117
+ else
1118
+ {
1119
+ Saved->TryGetStringField(TEXT("error"), Reason);
1120
+ }
1121
+ const TArray<TSharedPtr<FJsonValue>>* Diagnostics = nullptr;
1122
+ if (Saved->TryGetArrayField(TEXT("saveDiagnostics"), Diagnostics) && Diagnostics)
1123
+ {
1124
+ Row->SetArrayField(TEXT("saveDiagnostics"), *Diagnostics);
1125
+ }
1126
+ }
1127
+ if (Status == TEXT("saved")) ++SavedCount;
1128
+ else if (Status == TEXT("notDirty")) ++NotDirtyCount;
1129
+ else
1130
+ {
1131
+ Status = TEXT("failed");
1132
+ ++FailedCount;
1133
+ if (FirstFailure.IsEmpty()) FirstFailure = FString::Printf(TEXT("%s: %s"), *Package->GetName(), *Reason);
1134
+ }
1135
+ Row->SetStringField(TEXT("status"), Status);
1136
+ if (!Reason.IsEmpty()) Row->SetStringField(TEXT("reason"), Reason);
1137
+
1138
+ const FMCPMeshUsersFileState After = MCPMeshUsersReadFile(Package);
1139
+ Row->SetBoolField(TEXT("existsOnDisk"), After.bExists);
1140
+ Row->SetNumberField(TEXT("fileSizeAfter"), static_cast<double>(After.Size));
1141
+ if (After.bExists) Row->SetStringField(TEXT("modifiedUtcAfter"), After.Stamp.ToIso8601());
1142
+ const bool bFileChanged = After.bExists && (!Before.bExists || After.Size != Before.Size || After.Stamp != Before.Stamp);
1143
+ Row->SetBoolField(TEXT("fileChanged"), bFileChanged);
1144
+ if (bFileChanged) ++FileChangedCount;
1145
+ Row->SetBoolField(TEXT("dirtyNow"), Package->IsDirty());
1146
+ PackageRows.Add(MakeShared<FJsonValueObject>(Row));
1147
+ }
1148
+
1149
+ Result->SetNumberField(TEXT("packageCount"), PackageOrder.Num());
1150
+ Result->SetArrayField(TEXT("packages"), PackageRows);
1151
+ Result->SetBoolField(TEXT("componentRowsTruncated"), ComponentRows < MatchedComponents);
1152
+ Result->SetNumberField(bDryRun ? TEXT("wouldRecreate") : TEXT("recreated"), bDryRun ? (bRecreate ? MatchedComponents : 0) : Recreated);
1153
+ Result->SetNumberField(TEXT("splineCopiesRebuilt"), SplineCopiesRebuilt);
1154
+ Result->SetNumberField(TEXT("savedCount"), SavedCount);
1155
+ Result->SetNumberField(TEXT("notDirtyCount"), NotDirtyCount);
1156
+ Result->SetNumberField(TEXT("failedCount"), FailedCount);
1157
+ Result->SetNumberField(TEXT("filesChanged"), FileChangedCount);
1158
+ Result->SetStringField(TEXT("saveNote"),
1159
+ TEXT("Only the packages listed here are saved. A SplineMeshComponent's package is marked dirty first because its collision copy is saved with the actor; ")
1160
+ TEXT("a package holding only StaticMeshComponents has nothing collision-related of its own to write and is reported notDirty unless it already had unsaved edits. ")
1161
+ TEXT("wasDirty=true means the package held other unsaved edits before this call, and saving it wrote those too."));
1162
+ if (Users.IsEmpty())
1163
+ {
1164
+ Result->SetStringField(TEXT("zeroMatchNote"), bPartitioned
1165
+ ? TEXT("No loaded component uses these meshes. On a World Partition map the users may be in unloaded cells: load them with level(load_actor_descs) and run this again.")
1166
+ : TEXT("No loaded component uses these meshes with the componentClass given."));
1167
+ }
1168
+ if (bDryRun)
1169
+ {
1170
+ Result->SetStringField(TEXT("dryRunNote"),
1171
+ TEXT("dryRun defaults to TRUE for this action: it lists the components that would be rebuilt and the packages that would be saved, with each component's current collision. Pass dryRun=false to rebuild and save them."));
1172
+ }
1173
+
1174
+ const bool bChanged = Recreated > 0 || SavedCount > 0;
1175
+ if (bChanged)
1176
+ {
1177
+ MCPSetUpdated(Result);
1178
+ }
1179
+ Result->SetBoolField(TEXT("unchanged"), !bChanged);
1180
+
1181
+ if (FailedCount > 0)
1182
+ {
1183
+ Result->SetBoolField(TEXT("success"), false);
1184
+ Result->SetStringField(TEXT("error"), FString::Printf(
1185
+ TEXT("%d of %d packages did not save. The first: %s"), FailedCount, PackageOrder.Num(), *FirstFailure));
1186
+ }
1187
+
1188
+ MCPSetNoRollback(Result,
1189
+ TEXT("Rebuilding a component's collision discards the copy it held and rebuilds it from the mesh as it is now, and saving overwrites each actor package on disk. ")
1190
+ TEXT("Neither the old copy nor the old file is kept, and the bridge has no action that restores a package file; source control holds the previous revision. ")
1191
+ TEXT("Running this again rebuilds from the same mesh and lands on the same state."));
1192
+ return MCPResult(Result);
1193
+ }
1194
+
716
1195
  // ---------------------------------------------------------------------------
717
1196
  // test_component_overlap (#914)
718
1197
  // ---------------------------------------------------------------------------
@@ -232,6 +232,8 @@ TSharedPtr<FJsonValue> FLevelHandlers::ReplaceActorsWithAsset(const TSharedPtr<F
232
232
  // level(rebuild_brush): UEditorActorSubsystem::RebuildBrush.
233
233
  TSharedPtr<FJsonValue> FLevelHandlers::RebuildBrush(const TSharedPtr<FJsonObject>& Params)
234
234
  {
235
+ // Engines before 5.9 refuse before the actor is looked up; its parameters are read either way.
236
+ MCPReadParamsAhead(Params, { TEXT("actorLabel"), TEXT("actorPath") });
235
237
  const FString BuilderClassName = OptionalString(Params, TEXT("builderClass"));
236
238
  const TSharedPtr<FJsonObject>* BuilderPropsField = nullptr;
237
239
  const bool bHasBuilderProps = TryGetObjectParam(Params, TEXT("builderProperties"), BuilderPropsField) && BuilderPropsField && (*BuilderPropsField).IsValid();