Do you know Interchange Import ? Use a different content path string for each import.
Hi,
Yes, I assume we know how to use the interchange import. Here is some sample code we use:
UInterchangeManager* ImportManager = UInterchangeManager::GetInterchangeManagerScripted();
UInterchangeSourceData* SourceData = ImportManager->CreateSourceData(InFilePath);
FImportAssetParameters ImportAssetParams;
ImportAssetParams.bIsAutomated = true;
// ImportAssetParams.OverridePipelines = ImportPipelines;
ImportAssetParams.OnAssetsImportDone.BindUFunction(this, "OnAssetsImportDone");
ImportManager->ImportAsset("/Game/ImportedAssets", SourceData, ImportAssetParams);
void AImportedActor::OnAssetsImportDone(const TArray<UObject*>& Objects)
{
for (int i = 0; i < Objects.Num(); i++)
{
if(Object[i])
{
UStaticMesh* ImportedStaticMesh = Cast<UStaticMesh>(Objects[i]);
if (ImportedStaticMesh)
{
this->GetStaticMeshComponent()->SetStaticMesh(ImportedStaticMesh);
}
}
}
}
It works fine if we import a single mesh, like a chair or a sofa. When importing whole scenes with gltf, thatās when problems happen. We also use the datasmith interchange āLoad fileā function, but it just crashes the packaged game or gives us bad results.
Main problem is, basically non of the runtime importing pipelines work anymore in 5.3 to import whole scenes, because it is either crashing, or the materials are missing.
It also seems like that whe importing a single mesh, it does not have collision.
Do you mean a different folder is necessary for each import?
Does this apply when trying to import whole scenes at runtime in packaged build?
i only used import with visual scripting. I used datamsith after interchange didnt work out of the box but now only interchange.
Yes Pipline didnt work for me either in 5.2 but in 5.4 it should. I am currentlich on 5.3 but have no interest in testing it out at the moment.
I had occasional crashes with datasmith as well with interchange.
gltf imports, that got less frequent crashes with some Handmade waiting time Arround one Loading cycle (severalseconds) . But async Loading is to cool to have, so I tried further out, and the trick for me was that each import scene node call gets its own content path.
Since I only use it on single parts and only one time I canāt tell the difference to your situation. By the way i use .glb files und u .datasmith thats maybe also a difference.
Do you have proper collision too?
By 5.4, do you mean you use the UE5-Main branch from git?
Also, does async loading work for you properly? For GLB files, async loading leads to lost materials in 5.3.2.
Hi Flavien,
Could you please confirm if interchange can import glTF files with collision at runtime in packaged apps? In 5.3.2, it seems like they are losing collision. In the editor, it works fine.
Yes, i am setting up the collisions at runtime .
I setting my material in Unreal also after import. So your problem canāt occur for me.
Im using at the moment 5.3, but for packaging i will have to use a custom compiled version with allow CpU access [Feature Request] Interchange direct Import to DynamicMesh at runtime - #7 by SimPro2023
Iām sure there must be something obvious that iāve missed. Iāve set this up the way it is shown in the docs and while it does import my OBJ file, i canāt get it to spawn the asset into the scene.
I have a little screenshot of my BP actor that i have placed in the scene. Very simple. Iām using Import Scene which i thought would make UE place the asset into the scene once itās done with the import. Iām not overriding Pipelines or anything.
Iām using the First Person template project to test in. Adding my BP actor to the scene. Run in PIE and run my Do Import function. It brings up the Import settings dialog and i press the āImportā button. All looks to be good. I get a little msg that says āImport Done.ā The imported static mesh object shows up in the Content Browser in the correct folder. No Errors or Warnings in the Output Log. The imported static mesh looks fine. I can manually drag-n-drop it into my scene.
So i can successfully import the asset but it does not spawn into the scene autmoatically. AND there doesnāt appear to be a way to spawn the imported static mesh manually because the BP functions do not return a reference to the static mesh object. Is it possible to take the Source Data object and get a reference to all the objects that resulted from that import?
I can see in someoneās example C++ code above that it looks like this in only possible in C++?
iāve tried this in UE 5.2 and 5.3 and get the same results. My OBJ file is a simple sphere exported from Maya. Any help would be appriciated.
thx-e
OBJ does not contain scene info, they are usually just models so scene import will not do what you want.
Could you try to do an asset import and then spawn the resulting static mesh yourself?
For that you can tweak the ImportAssetParameters so you get a custom event that is called once import is done + gives you the created objects. You will have to filter to get the static meshes.
Hi Flavien,
Could you confirm if collision is imported too at runtime in packaged builds?
AFAIK no.
We cannot build simple collision at runtime.
The easiest would be to change the collision complexity to use convex as simple but it does not look straightforward at runtime. There was an option on the datasmith runtime import but it is not there for interchange.
I didnt try it yet. But Unreal Scans for Collision meshes in the same folder as the import target. You could try too lay Mesh for Collision with the correct ending .UCX ( i guess) in the exact same folder.
Maybe it works. import.glb and import.glb.UCX put in the same folder importing import.glb would be my test if it works.
remember to reduce the number of vertices after the test that it is performant.
How about complex collision?
I wonder how are we supposed to manipulate the imported meshes, if we can not trace against themā¦?
Did you test it ? Complex Collision should work. I see the problem that a complex collision is very performance hungry on some meshes with many vertices. if u only use it for tracing it will work, but if you want to simulate the object i would use a simple as possible
convex hull.
I tried it in a packaged build in 5.3 and unfortunately, collision does not work at all. It does in the editor, but not in a packaged build.
thanks for the reply. this does look like the step i was missing.
However, Iāve decided to wait till 5.4 when the FBX interchange pipeline becomes officially supported by Epic.
-e
I have the same issue, how would we enable to use complex collision at runtime?
I cannot line trace to the imported meshes in a packaged build but it works in the editor
Hi, Do you use a source build?
If so, do the following:
- Replace the IsRuntime function inside the BodySetup.cpp file around line 378 with this:
bool IsRuntime(const UBodySetup* BS)
{
#if !WITH_EDITOR
const UWorld* EngineWorld = GEngine && GEngine->GetWorldContexts().Num() > 0 ? GEngine->GetWorldContexts()[0].World() : nullptr;
#else
const UWorld* EngineWorld = nullptr;
#endif
const UObject* OwningObject = BS->GetOuter();
const UWorld* World = OwningObject && OwningObject->GetWorld() ? OwningObject->GetWorld() : EngineWorld;
return World && World->IsGameWorld();
}
- Inside the StaticMesh.cpp file, set bAllowCPUAccess to true inside the constructor around line 3376 for example.
- Rebuild the engine and enjoy.
I tried the interchange with 5.4 Preview 1 and it donāt seems to have a lot of improvement. GLB still donāt have collision in packaged build. FBX work in editor but with weird textures but model didnāt open in a packaged build.