# \[Feature Request\] Interchange direct Import to DynamicMesh at runtime

**URL:** <https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927>\
**Category:** Pipeline & Plugins\
**Tags:** unreal-engine, import, geometry-script, runtime, Blueprint\
**Created:** [July 11, 2023, 11:25am UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927 "2023-07-11T11:25:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [July 11, 2023, 11:25am UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/1 "2023-07-11T11:25:12Z")

</div>

Interchange ImportScene generates an Static Mesh Actor from an .gltf-File.This Static Mesh Actor needs the flag “Allow CPU Access” so that it can be read by CopyfromStaticMesh to make a dynamic mesh.

The dynamicmesh is the requirement for many geometry script functions.

This Option “Allow CPU Access” is located inside the Mesh Editor Subsystem so it is not reachable out of the box at the moment. Espacially runtime imported files (after Compiling) are a problem right now .

Interchange ist quite new and under development so it should be possible not to forget about many Developers, that want to react on 3D Data during runtime by using Geometry Script function. (For Example loading a custom Avater or a self made piece of Deco )

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [August 1, 2023, 8:19am UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/2 "2023-08-01T08:19:12Z")

</div>

> [@SimPro2023](#):
>
> “Allow CPU Access”

should be an Import Option for Interchange.

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [August 22, 2023, 2:21pm UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/3 "2023-08-22T14:21:11Z")

</div>

There is already a system integrated in Interchange, that is called UserDefinedAttributesAPI, I am going to use this to modify the flag ballowcpuaccess on static meshes, that are imported via interchange. Advices, examples even of unfinished tries are very wanted. Here some Reference I found in the unreal docs: [unreal.InterchangeUserDefinedAttributesAPI — Unreal Python 5.1 (Experimental) documentation](https://docs.unrealengine.com/5.1/en-US/PythonAPI/class/InterchangeUserDefinedAttributesAPI.html)

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [September 7, 2023, 3:06pm UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/4 "2023-09-07T15:06:00Z")

</div>

I am still working to find a solution. Update: i narrowed down the missing functionality in UE 5.2  
Here is a log from the packaged .exe with some extra custom logging to show better, what exactly is happening:

> LogInterchangeEngine: Display: Interchange start importing source [C:/…\*.step.glb]  
> In Staticmesh.cpp BuildFromMeshDescription is called Line 6516  
> In StaticMesh-cpp InitResources was called  
> In Staticmesh.cpp FStaticMeshRenderData:InitResources is called Line 1866  
> LogInterchangeEngine: Display: In InterchangeTaskCompletion.cpp Line 120  
> In InterchangeTaskCompletion.cpp Line 120 Registerallcomponents (actor) was called  
> In InterchangeTaskCompletion.cpp Line 33 UE::Interchange::FTaskPreAsyncCompletion::DoTask was called that calls next ReleaseTranslatorsSource()  
> ImportSceneObjectDone wurde ausgeführt für Index:::19  
> InterchangeManager.cpp 343 FimportAsyncHelper::Cleanup  
> Read Imported Data  
> LogGeometry: Warning: GeometryScriptError: CopyMeshFromStaticMesh: Requested LOD Type is not available

The interchange import doesn’t fill out the needed CPU-Data i guess, because in most cases it is not needed. I Found a piece of Code Comment:

> FStaticMeshLODResourcesToDynamicMesh can be used to create a FDynamicMesh3 from a FStaticMeshLODResources, which is the variant of the mesh in a StaticMesh Asset used for rendering (and which is available at runtime). The FStaticMeshLODResources has vertices duplicated at any split UV/normal/tangent/color, ie in the overlays there will be a unique overlay element for each base mesh vertex.

my next try is i guess is to try if i can manage to extend Interchange somehow to fill a FDynamicMesh3 object.

The Source code of the Engine has a real good quality and is at the same time very big and complex. Advices or motivational speeches will be appreciated.

If someone wonders what this ominous CPU-Data is, here a piece of sourcecode found in (staticmesh.cpp Line 1519 UE 5.2) ( it is not called in my case so only useful for understanding) :

> void FStaticMeshLODResources::DiscardCPUData()  
> {  
> VertexBuffers.StaticMeshVertexBuffer.CleanUp();  
> VertexBuffers.PositionVertexBuffer.CleanUp();  
> VertexBuffers.ColorVertexBuffer.CleanUp();  
> IndexBuffer.Discard();  
> DepthOnlyIndexBuffer.Discard();
> 
> if (AdditionalIndexBuffers)  
> {  
> AdditionalIndexBuffers-\>ReversedIndexBuffer.Discard();  
> AdditionalIndexBuffers-\>ReversedDepthOnlyIndexBuffer.Discard();  
> AdditionalIndexBuffers-\>WireframeIndexBuffer.Discard();  
> }
> 
> #if RHI\_RAYTRACING  
> RayTracingGeometry.RawData.Discard();  
> #endif  
> }  
> It appears to be so simple. Maybe someone want to bite into it and share whatever comes along.

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [September 13, 2023, 3:52pm UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/5 "2023-09-13T15:52:00Z")

</div>

Is here some #Interchange Framework Expert ?

1. Which is the most straight forward way of Implementing an Import Function that imports directly into #DynamicMesh ?

(Post packaging Runtime Import of .gltf Files)

> From Website: The core component that enables Geometry Script is the **UDynamicMesh** object.

I know that during Import in (post packaged) Game.exe the function BuildFromMeshDescription is called in staticmesh.cpp

Line 6516 C:\UE\UnrealEngine\Engine\Source\Runtime\Engine\Private\StaticMesh.cpp:

But i have troubles to locate the source code that delivers these imported Data from interchange. There are some virtual function that are maybe overwritten by generated source code after compiling that makes finding difficult.

> void UStaticMesh::BuildFromMeshDescription(const FMeshDescription& MeshDescription, FStaticMeshLODResources& LODResources)

1. Where in the Interchange System is the MeshDescription generating Function in the Source Code ?

My general Problem is that in the “normal” Static Mesh Import Result the CPU-Data is not imported, although the interchange importer has it for sure. The CPU-Data I am looking for is nothing magical, it’s only the unoptimized Vertexes:

> staticmesh.cpp 1519 Funktion:  
> void FStaticMeshLODResources::DiscardCPUData()  
> {  
> VertexBuffers.StaticMeshVertexBuffer.CleanUp();  
> VertexBuffers.PositionVertexBuffer.CleanUp();  
> VertexBuffers.ColorVertexBuffer.CleanUp();  
> IndexBuffer.Discard();  
> DepthOnlyIndexBuffer.Discard();  
> UE\_LOG(LogStaticMesh, Display, TEXT(“In StaticMesh.cpp CPU DATA is Discarded”));  
> if (AdditionalIndexBuffers)  
> {  
> AdditionalIndexBuffers-\>ReversedIndexBuffer.Discard();  
> AdditionalIndexBuffers-\>ReversedDepthOnlyIndexBuffer.Discard();  
> AdditionalIndexBuffers-\>WireframeIndexBuffer.Discard();  
> }
> 
> #if RHI\_RAYTRACING  
> RayTracingGeometry.RawData.Discard();  
> #endif  
> }

---

<div class="post-metadata">

**Author:** ![1FoNo1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@1FoNo1](https://forums.unrealengine.com/u/1FoNo1)\
**Post date:** [November 2, 2023, 1:41am UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/6 "2023-11-02T01:41:49Z")

</div>

hi, thank you for posting this up!  
I need the feature as well!  
I am using Niagara system to sample dynamic generated mesh which “Allow CPU access” is turned off by default! And this causes it sampled improperly!  
So annoying, did you find a solution yet?

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [November 7, 2023, 12:38pm UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/7 "2023-11-07T12:38:14Z")

</div>

Hi, Yes, I did find a solution:

I Just recompiled the complete Unreal Engine (5.2) with this little change:

in Line 3334 in the constructor of the static mesh in C:\UE\UnrealEngine\Engine\Source\Runtime\Engine\Private\StaticMesh.cpp I added this line:

```auto

bAllowCPUAccess = true;

```

And it is working (not direct, but i can import from the static Mesh that was created by interchange to dynamic mesh )  
Extra Info Fastbuild:  
I also tried with bDoFastBuild = true; AND false. In both cases it is working, what surprised me somehow. Does someone know what Dofastbuild is exactly ?

1. This is a quite dirty solution so far, since every static mesh will have CPU Access Data,  
costing resources. So we should make it smarter.

2. A Script Node with a Singleton Boolean that can be switched on and off, would do the trick. Every time a static mesh is constructed, it could check the Value of this Bool Variable.

3. The Interchange Manager is already a singleton object so I added:

```auto
InterchangeManager.h line 279:
USTRUCT(BlueprintType)
struct INTERCHANGEENGINE_API FImportAssetParameters

InterchangeManager.h line 295:
	// Define a Bool that the static Mesh constructor checks on creating a new static mesh 
	// The constructor than sets its own bool accordingly
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interchange|ImportAsset")
	bool bKeepCPUData = false;

```

but had some troubles with including interchangemanager.h in staticmesh.cpp (Now, I know it better, you have to rebuild the solution file every time you add a new include. )

I hope this change would make it in the Unreal Engine, so that the recompilation is no longer necessary to use this feature.

I hope it Helps 👍

---

<div class="post-metadata">

**Author:** ![1FoNo1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@1FoNo1](https://forums.unrealengine.com/u/1FoNo1)\
**Post date:** [November 8, 2023, 3:51pm UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/8 "2023-11-08T15:51:57Z")

</div>

This is awesome!! Thanks for posting it up!

---

<div class="post-metadata">

**Author:** ![SimPro2023](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/simpro2023/32/708849_2.png) [@SimPro2023](https://forums.unrealengine.com/u/SimPro2023)\
**Post date:** [August 13, 2024, 10:03am UTC](https://forums.unrealengine.com/t/feature-request-interchange-direct-import-to-dynamicmesh-at-runtime/1225927/9 "2024-08-13T10:03:27Z")

</div>

As of Version 5.4, Import from Static Mesh to dynamic mesh works even on Runtime !  
Thank you, Epic Games Dev Team and Forum Team !
