Zeclown
(Zeclown)
November 11, 2016, 4:44pm
1
Hey, I’m trying to get a hold of a MaterialParameterCollection in C++. Here is the code I am using:
static ConstructorHelpers::FObjectFinder<UMaterialParameterCollection> MaterialCol(TEXT("MaterialParameterCollection'/Game/Characters/Materials/RoxyBody'"));
if (MaterialCol.Succeeded())
{
BodyMaterialCollection = reinterpret_cast<UMaterialParameterCollection*>(MaterialCol.Object);
}
However I get the following error on compilation
Severity Code Description Project File Line Suppression State
Error C2664 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)': cannot convert argument 1 from 'UMaterialParameterCollection *' to 'UObject *' DarklightProject C:\Program Files (x86)\Epic Games\4.12\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h 105
UMaterialParameterCollection inherits from UObject, so I have no idea why it is not able to convert it.
Jambax
(Jambax)
November 11, 2016, 11:08pm
2
You shouldn’t need to cast the object at all, just use BodyMaterialCollection = MaterialCol.Object.
Bear in mind, you can’t change any properties of that collection asset. Each world creates an instance of a material parameter collection, and you should instead modify that instance. See UKismetMaterialLibrary for more details.
Zeclown:
MaterialCol
I have same issue and your suggestion @ TheJamsh didn’t fix it.
Code in constructor:
static ConstructorHelpers::FObjectFinder<UMaterialParameterCollection> objectType(TEXT("/Script/Engine.MaterialParameterCollection'/Game/ThirdPerson/Blueprints/MPC_01.MPC_01'"));
if (objectType.Succeeded()){
collection = objectType.Object;
UE_LOG(LogTemp, Warning, TEXT(" ktx ---- AChar_A >> Material Parameter Collection found"));
}
… and error:
1>C:\Program Files\Epic Games\UE_5.1\Engine\Source\Runtime\CoreUObject\Public\UObject\ConstructorHelpers.h(110): error C2664: ‘void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)’: cannot convert argument 1 from ‘T *’ to ‘UObject *’
… any suggestion?
This is how i fixed it in 5.1:
inside constructor - MPC_A is a public pointer variable of UMaterialParameterCollection
MPC_A = Cast<UMaterialParameterCollection>(StaticLoadObject(UMaterialParameterCollection::StaticClass(), nullptr, TEXT("/Script/Engine.MaterialParameterCollection'/Game/ThirdPerson/Blueprints/MPC_01.MPC_01'")));
you have to include these in header file:
include “Materials/MaterialParameterCollection.h”
include “Materials/MaterialParameterCollectionInstance.h”
include “Kismet/KismetMaterialLibrary.h”
… access parameters inside other functions/methods
UKismetMaterialLibrary::SetScalarParameterValue(GetWorld(), MPC_A, "mpc01_svar_01", 7.0);
UKismetMaterialLibrary::SetVectorParameterValue(GetWorld(), MPC_A, "mpc01_vvar_01", FLinearColor::Blue);