Author Topic: "CreateGraphInstance" or "DuplicateGraphInstance" called twice crashes UE4  (Read 1426 times)

Hi there!

When using "CreateGraphInstance" or "DuplicateGraphInstance" twice on the same Factory or Graph Instance, UE4 crashes with the error message below. Please, is there a better way or a work around this issue?

It happens at runtime. The first instance is created at the start of the game, the second instance is created depending on the user action during the game.

Tested with:
- Unreal Engine 4.22.1
- Ray Tracing activated and deactivated.
- RTX 2060
- AMD Ryzen 5 2600
- Windows 10 (Release 1809)

From the dump file:
Exception information: The thread tried to read from or write to a virtual address for which it does not have the appropriate access.
Exception code: 0xC0000005

UE4 crash report:

Quote
Fatal error!

Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000088

UE4Editor_D3D12RHI!SetRayTracingShaderResources<FD3D12RayTracingLocalResourceBinder>() [d:\build\++ue4\sync\engine\source\runtime\d3d12rhi\private\d3d12raytracing.cpp:2287]
UE4Editor_D3D12RHI!FD3D12CommandContext::RHISetRayTracingHitGroup() [d:\build\++ue4\sync\engine\source\runtime\d3d12rhi\private\d3d12raytracing.cpp:2643]
UE4Editor_RHI!FRHICommandSetRayTracingHitGroup::Execute() [d:\build\++ue4\sync\engine\source\runtime\rhi\public\rhicommandlistcommandexecutes.inl:602]
UE4Editor_RHI!FRHICommandListExecutor::ExecuteInner_DoExecute() [d:\build\++ue4\sync\engine\source\runtime\rhi\private\rhicommandlist.cpp:325]
UE4Editor_RHI!FExecuteRHIThreadTask::DoTask() [d:\build\++ue4\sync\engine\source\runtime\rhi\private\rhicommandlist.cpp:384]
UE4Editor_RHI!TGraphTask<FExecuteRHIThreadTask>::ExecuteTask() [d:\build\++ue4\sync\engine\source\runtime\core\public\async\taskgraphinterfaces.h:842]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4\sync\engine\source\runtime\core\private\async\taskgraph.cpp:686]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4\sync\engine\source\runtime\core\private\async\taskgraph.cpp:582]
UE4Editor_RenderCore!FRHIThread::Run() [d:\build\++ue4\sync\engine\source\runtime\rendercore\private\renderingthread.cpp:282]
UE4Editor_Core!FRunnableThreadWin::Run() [d:\build\++ue4\sync\engine\source\runtime\core\private\windows\windowsrunnablethread.cpp:96]

Last Edit: May 17, 2019, 04:45:02 pm

Trying to find the issue and a work around, so here more info and a project to reproduce the error.
Precision, the game crashes with RayTraycing off if I do AsyncRendering, otherwise it just throw an error.

The warning below seems to be related to this: https://answers.unrealengine.com/questions/194067/c-spawnactor-bug.html

Quote
LogUObjectGlobals: Warning: Gamethread hitch waiting for resource cleanup on a UObject (SubstanceTexture2D /Engine/Transient.GameEngine_0:BP_ScGameInstance_C_0.BP_MainUI_C_0.WidgetTree_0.SceneCenter.baseColor) overwrite took   0.00ms. Fix the higher level code so that this does not happen.

In short it says:
Quote
... this particular error occurs when attempting to create a new object over an existing object that hasn't been completely cleaned up. The most likely cause for this is that the new object is being created with the same name/class/outer as an existing component, when the existing object cannot immediately clean up its resources in BeginDestroy.

Another log from the Standalone Game:
Quote
[2019.05.18-21.11.02:885][940]LogWindows: Error: === Critical error: ===
[2019.05.18-21.11.02:885][940]LogWindows: Error:
[2019.05.18-21.11.02:885][940]LogWindows: Error: Fatal error!
[2019.05.18-21.11.02:885][940]LogWindows: Error:
[2019.05.18-21.11.02:885][940]LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000008
[2019.05.18-21.11.02:885][940]LogWindows: Error:
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0a99c6 UE4Editor-CoreUObject.dll!UObjectBaseUtility::MarkPackageDirty() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbaseutility.cpp:137]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9b04af63a UE4Editor-SubstanceCore.dll!Substance::Helpers::UpdateTextures() [d:\build\++portal+dev-marketplace+full\sync\localbuilds\plugintemp\hostproject\plugins\substance\source\substancecore\private\substancecorehelpers.cpp:903]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9b04a65fa UE4Editor-SubstanceCore.dll!Substance::Helpers::RenderSync() [d:\build\++portal+dev-marketplace+full\sync\localbuilds\plugintemp\hostproject\plugins\substance\source\substancecore\private\substancecorehelpers.cpp:218]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9b04add5f UE4Editor-SubstanceCore.dll!USubstanceUtility::SyncRendering() [d:\build\++portal+dev-marketplace+full\sync\localbuilds\plugintemp\hostproject\plugins\substance\source\substancecore\private\substanceutility.cpp:385]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9b04b85b7 UE4Editor-SubstanceCore.dll!USubstanceUtility::execSyncRendering() [d:\build\++portal+dev-marketplace+full\sync\localbuilds\plugintemp\hostproject\plugins\substance\source\substancecore\classes\substanceutility.h:38]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9cde9bac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0900e2 UE4Editor-CoreUObject.dll!UObject::CallFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:904]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0acbc1 UE4Editor-CoreUObject.dll!UObject::ProcessContextOpcode() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:2314]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:885][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae378 UE4Editor-CoreUObject.dll!UObject::ProcessInternal() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1058]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9cde9bac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0adf07 UE4Editor-CoreUObject.dll!UObject::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1464]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8a6329e UE4Editor-UMG.dll!UUserWidget::NativeConstruct() [d:\build\++ue4\sync\engine\source\runtime\umg\private\userwidget.cpp:1460]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8abf8a1 UE4Editor-UMG.dll!UWidget::TakeWidget_Private() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:787]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8a0f4d7 UE4Editor-UMG.dll!UCanvasPanelSlot::BuildSlot() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\canvaspanelslot.cpp:29]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8a84d95 UE4Editor-UMG.dll!UCanvasPanel::RebuildWidget() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\canvaspanel.cpp:59]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8abf233 UE4Editor-UMG.dll!UWidget::TakeWidget_Private() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:722]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8a914f6 UE4Editor-UMG.dll!UUserWidget::RebuildWidget() [d:\build\++ue4\sync\engine\source\runtime\umg\private\userwidget.cpp:893]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8abf233 UE4Editor-UMG.dll!UWidget::TakeWidget_Private() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:722]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8abf0fd UE4Editor-UMG.dll!UWidget::TakeWidget() [d:\build\++ue4\sync\engine\source\runtime\umg\private\components\widget.cpp:709]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8a08464 UE4Editor-UMG.dll!UUserWidget::AddToScreen() [d:\build\++ue4\sync\engine\source\runtime\umg\private\userwidget.cpp:1074]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c8ad1237 UE4Editor-UMG.dll!UUserWidget::execAddToViewport() [d:\build\++ue4\sync\engine\source\runtime\umg\public\blueprint\userwidget.h:208]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9cde9bac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0900e2 UE4Editor-CoreUObject.dll!UObject::CallFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:904]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0acbc1 UE4Editor-CoreUObject.dll!UObject::ProcessContextOpcode() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:2314]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce085efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0ae378 UE4Editor-CoreUObject.dll!UObject::ProcessInternal() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1058]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9cde9bac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ce0adf07 UE4Editor-CoreUObject.dll!UObject::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1464]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c9369ff3 UE4Editor-Engine.dll!AActor::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\engine\private\actor.cpp:769]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c9337358 UE4Editor-Engine.dll!AActor::BeginPlay() [d:\build\++ue4\sync\engine\source\runtime\engine\private\actor.cpp:3383]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c9341af6 UE4Editor-Engine.dll!AActor::DispatchBeginPlay() [d:\build\++ue4\sync\engine\source\runtime\engine\private\actor.cpp:3343]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ca45c559 UE4Editor-Engine.dll!AWorldSettings::NotifyBeginPlay() [d:\build\++ue4\sync\engine\source\runtime\engine\private\worldsettings.cpp:253]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c99c2721 UE4Editor-Engine.dll!AGameStateBase::HandleBeginPlay() [d:\build\++ue4\sync\engine\source\runtime\engine\private\gamestatebase.cpp:177]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ca416fbe UE4Editor-Engine.dll!UWorld::BeginPlay() [d:\build\++ue4\sync\engine\source\runtime\engine\private\world.cpp:3946]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ca33d420 UE4Editor-Engine.dll!UEngine::LoadMap() [d:\build\++ue4\sync\engine\source\runtime\engine\private\unrealengine.cpp:12415]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ca2e19a7 UE4Editor-Engine.dll!UEngine::Browse() [d:\build\++ue4\sync\engine\source\runtime\engine\private\unrealengine.cpp:11643]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9ca36a418 UE4Editor-Engine.dll!UEngine::TickWorldTravel() [d:\build\++ue4\sync\engine\source\runtime\engine\private\unrealengine.cpp:11841]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff9c9990011 UE4Editor-Engine.dll!UGameEngine::Tick() [d:\build\++ue4\sync\engine\source\runtime\engine\private\gameengine.cpp:1350]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff757776bb1 UE4Editor.exe!FEngineLoop::Tick() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3967]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff75778554c UE4Editor.exe!GuardedMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launch.cpp:168]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff7577855ca UE4Editor.exe!GuardedMainWrapper() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:145]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff75779316c UE4Editor.exe!WinMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:275]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ff757795b8e UE4Editor.exe!__scrt_common_main_seh() [d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ffa29677974 KERNEL32.DLL!UnknownFunction []
[2019.05.18-21.11.02:886][940]LogWindows: Error: [Callstack] 0x00007ffa2980a271 ntdll.dll!UnknownFunction []

I made a test project to reproduce the bug. You can download the file from this link:
https://drive.google.com/file/d/1GVvkxoh7SxEsRq6mOhBvUkBBfEm67uCR/view

It doesn't show the error messages, but you can see that the previous textures of the Graph are lost. It's the same problem I get in the game. I guess it's this issue that causes the crash when RayTracing is activated in the Game. For unknow reason, it doesn't crash with the test project.



About the test project, most logic is in MyPlayerController. At begin play, the Sphere actor creates a Graph Instance.

Once the game is launched here the keys to press to see the result:
- press "G" to create a Graph Instance on a sphere
- press "H" to spawn a sphere with a new Graph Instance
- press "J" to change the color of one Graph Instance

To see the problem, press H to spwan a sphere. The previous Graph looses his textures. It might be an issue with the texture naming.

Hope that helps. I tried many ways, but it didn't work so far. If there is a temporary solution, please let me know.
Thanks!

Not sure if it's something I'm doing wrong but this is the temporary solution found. It's used each time a substance graph intance is created to avoid textures with the same name.
For C++, use SustanceTexture->Rename();
See more: https://api.unrealengine.com/INT/API/Runtime/CoreUObject/UObject/UObject/Rename/index.html

For Blueprint: Just create a rename function in your library.

Code: [Select]
UFUNCTION(BlueprintCallable, Category = "Substance")
static void RenameSubstanceTexture(USubstanceTexture2D* SubstanceTexture, FString NewName);

void MyLibrary::RenameSubstanceTexture(USubstanceTexture2D* SubstanceTexture, FString NewName)
{
  if (!SubstanceTexture) return;
  SubstanceTexture->Rename(*NewName, GetTransientPackage(), REN_ForceNoResetLoaders);
}

Then use it like this: