Skip to content

Commit 7b30bca

Browse files
authored
[src] Fix reloading of UE project that are saving absolute path to the scn file (#35)
1 parent f913dd7 commit 7b30bca

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Source/SofaUE5/Private/SofaContext.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,30 @@ void ASofaContext::loadSofaScene()
340340
return;
341341
}
342342

343+
// If the original path exists, just use it
343344
FString my_filePath = FPaths::ConvertRelativePathToFull(filePath.FilePath);
345+
if (!FPaths::FileExists(my_filePath)) // try to fix path
346+
{
347+
FString SubPath;
348+
int32 Index = my_filePath.Find(TEXT("Plugins\\"), ESearchCase::IgnoreCase, ESearchDir::FromEnd);
349+
if (Index == INDEX_NONE)
350+
Index = my_filePath.Find(TEXT("Plugins/"), ESearchCase::IgnoreCase, ESearchDir::FromEnd);
351+
352+
if (Index != INDEX_NONE)
353+
{
354+
SubPath = my_filePath.Mid(Index); // skip "Content/"
355+
my_filePath = FPaths::Combine(curPath, SubPath);
356+
}
357+
else
358+
{
359+
UE_LOG(SUnreal_log, Warning, TEXT("## ASofaContext::loadSofaScene: filePath is set but can't be loaded nor fixed: %s"), *my_filePath);
360+
return;
361+
}
362+
}
363+
344364
const char* pathfile = TCHAR_TO_ANSI(*my_filePath);
345365
int resScene = m_sofaAPI->load(pathfile);
346-
366+
347367
if (resScene < 0) {
348368
UE_LOG(SUnreal_log, Error, TEXT("## ASofaContext::loadSofaScene: Scene loading failed: %s | Error returned: %d"), *my_filePath, resScene);
349369
return;

Source/SofaUE5/Public/SofaContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class SOFAUE5_API ASofaContext : public AActor
100100
// Method to internally load SOFA default plugin dll
101101
void loadDefaultPlugin();
102102

103-
104103
void reconnectNodeGraph();
105104
void clearNodeGraph();
106105

0 commit comments

Comments
 (0)