Download

Material Parameter Collection Use in Code

So, I have a Material Parameter Collection defined in my game project, so I expose the asset through a UPROPERTY in my class:


UMaterialParameterCollection* MaterialParameterCollectionAsset

I then set that parameter to my MPC asset in-game, and instance a transient [FONT=Courier New]UMaterialParameterCollectionInstance in my class so I can manipulate the parameters at runtime through code. Which works, but it causes a crash on end-PIE:


Fatal error: [File:F:\joymachine\joyengine\Engine\Source\Developer\MessageLog\Private\Model\MessageLogListingModel.cpp] [Line: 81] 
Critical Error Package /Game/maps/UEDPIE_0_blandtown Object from PIE level still referenced. Shortest path from root: (Object is not currently rooted)

UE4Editor_Core!FDebug::AssertFailed() [f:\joymachine\joyengine\engine\source\runtime\core\private\misc\assertionmacros.cpp:349]
UE4Editor_Core!FMsg::Logf__VA() [f:\joymachine\joyengine\engine\source\runtime\core\private\logging\logmacros.cpp:64]
UE4Editor_MessageLog!FMessageLogListingModel::AddMessageInternal() [f:\joymachine\joyengine\engine\source\developer\messagelog\private\model\messageloglistingmodel.cpp:81]
UE4Editor_MessageLog!FMessageLogListingModel::AddMessages() [f:\joymachine\joyengine\engine\source\developer\messagelog\private\model\messageloglistingmodel.cpp:102]
UE4Editor_Core!FMessageLog::Flush() [f:\joymachine\joyengine\engine\source\runtime\core\private\logging\messagelog.cpp:198]
UE4Editor_Core!FMessageLog::~FMessageLog() [f:\joymachine\joyengine\engine\source\runtime\core\private\logging\messagelog.cpp:95]
UE4Editor_UnrealEd!UEditorEngine::EndPlayMap() [f:\joymachine\joyengine\engine\source\editor\unrealed\private\playlevel.cpp:485]
UE4Editor_UnrealEd!UEditorEngine::Tick() [f:\joymachine\joyengine\engine\source\editor\unrealed\private\editorengine.cpp:1878]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [f:\joymachine\joyengine\engine\source\editor\unrealed\private\unrealedengine.cpp:391]
UE4Editor!FEngineLoop::Tick() [f:\joymachine\joyengine\engine\source\runtime\launch\private\launchengineloop.cpp:3050]
UE4Editor!GuardedMain() [f:\joymachine\joyengine\engine\source\runtime\launch\private\launch.cpp:166]
UE4Editor!GuardedMainWrapper() [f:\joymachine\joyengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UE4Editor!WinMain() [f:\joymachine\joyengine\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:253]
kernel32
ntdll

And then in the logs, this seems to be the reason:


[2017.05.16-01.25.56:630][270]LogReferenceChain: (root) (native) (standalone) Class /Script/steelhunters.WorldSimulation->UE4Editor-CoreUObject.dll!UClass::AddReferencedObjects() [f:\joymachine\joyengine\engine\source\runtime\coreuobject\private\uobject\class.cpp:2560]
[2017.05.16-01.25.56:732][270]LogReferenceChain:   WorldSimulation /Script/steelhunters.Default__WorldSimulation->MaterialParameterCollection
[2017.05.16-01.25.56:781][270]LogReferenceChain:     MaterialParameterCollectionInstance /Script/steelhunters.Default__WorldSimulation:env_mpc_isntance->World
[2017.05.16-01.25.56:828][270]LogReferenceChain:       (target) World /Game/maps/UEDPIE_0_blandtown.blandtown
[2017.05.16-01.25.56:877][270]LogReferenceChain:   
[2017.05.16-01.25.56:925][270]LogReferenceChain: (root) (standalone) World /Game/maps/blandtown.blandtown->ParameterCollectionInstances
[2017.05.16-01.25.56:978][270]LogReferenceChain:   MaterialParameterCollectionInstance /Engine/Transient.MaterialParameterCollectionInstance_7->Collection
[2017.05.16-01.25.57:027][270]LogReferenceChain:     MaterialParameterCollection /Script/steelhunters.Default__WorldSimulation:env_mpc_asset->Outer
[2017.05.16-01.25.57:076][270]LogReferenceChain:       WorldSimulation /Script/steelhunters.Default__WorldSimulation->MaterialParameterCollection
[2017.05.16-01.25.57:126][270]LogReferenceChain:         MaterialParameterCollectionInstance /Script/steelhunters.Default__WorldSimulation:env_mpc_isntance->World
[2017.05.16-01.25.57:175][270]LogReferenceChain:           (target) World /Game/maps/UEDPIE_0_blandtown.blandtown

Is there something I’m missing? I’ve tried various means of handling the instance (including using [FONT=Courier New]UMaterialParameterCollectionInstance::RemoveFromRoot in the OnDestroy callback.

HALP

How are you creating the instance? I’ve used something like the following in a previous project and didn’t have any PIE errors:



UMaterialParameterCollectionInstance* inst;
...
inst = GetWorld()->GetParameterCollectionInstance(MaterialParameterCollectionAsset); 
inst->SetVectorParameterValue(etc...);

Pretty sure I didn’t need to do anything beyond that (e.g. tidying up)

2 Likes

Hrm, that’s actually different; I created a default subobject that I then (post-world initialization), setup like this:


MaterialParameterCollection->SetCollection( MaterialParameterCollectionAsset, GetWorld( ) );

What you did makes more sense; I’ll give it a shot.

Yeah MPC’s are instanced auto-magically by, just have to get that reference to them form the world.