GetLinearColorParameterValue returns false

I am trying to change a materials colour property at run-time while holding onto its previous colour to reset it after the given effect. My current setup works fine and changes the colour, but the function to get the current colour of the variable before changing it seems to simply return false, so when I go back to resetting the values, they are still at 0.f.

Here is some of the code I am using:

for (TActorIterator<AStaticMeshActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
	{
		FString ActorName = (ActorItr->GetName());
		if (ActorName.Contains("someName" , ESearchCase::IgnoreCase)
		{
			UMaterialInstanceDynamic* MatInst = NULL;
			if (MatInst == NULL) MatInst = ((USkeletalMeshComponent*)ActorItr->GetRootComponent())->CreateAndSetMaterialInstanceDynamic(0);

			if (!MatInst ->GetLinearColorParameterValue(TEXT("Colour1"), Colour))
                        //this returns false

			UMaterialInstanceDynamic* MatInst2 = NULL;
			if (MatInst2 == NULL) MatInst2 = ((USkeletalMeshComponent*)ActorItr->GetRootComponent())->CreateAndSetMaterialInstanceDynamic(1);

			if (!MatInst2->GetLinearColorParameterValue(TEXT("Colour2"), Colour2))
                        //this returns false
		}
	}

I’m aware that the function is returning false as that is whats in the source code. I was wondering if there was any way to get this value from the material or not?

Hi,

maybe the

UMaterialInstanceDynamic::GetVectorParameterValue(FName ParameterName, FLinearColor & OutValue)

could fit your needs ? If so, just try to replace

if (!MatInst ->GetLinearColorParameterValue(TEXT("Colour1"), Colour))

by

if (!MatInst->GetVectorParameterValue(TEXT("Colour1"), Colour))

Worked perfectly, don’t know why I didn’t consider that function, thanks!