Unreal/CarlaUE4/Plugins/RoadRunnerImporter/Source/RoadRunnerImporter/Private/RoadRunnerImportUtil.cpp
////////////////////////////////////////////////////////////////////////////////
// Helper function to set color parameter in a material instance
Helper function to set color parameter in a material instance
Helper function to set color parameter in a material instance
void FRoadRunnerImportUtil::SetColorParameter(UMaterialInstanceConstant* material,
	const FName& paramName, const FString& colorString, float alphaVal)
{
	if (colorString.IsEmpty())
	{
		return;
	}
	TArray<FString> colorStrings;
	int numElements = colorString.ParseIntoArray(colorStrings, TEXT(","), true);
	if (numElements != 3)
	{
		UE_LOG(RoadRunnerImporter, Error, TEXT("Error: %s's %s value is invalid"), *(material->GetFName().ToString()), *(paramName.ToString()));
		return;
	}
	float r = FCString::Atof(*(colorStrings[0]));
	float g = FCString::Atof(*(colorStrings[1]));
	float b = FCString::Atof(*(colorStrings[2]));
#if ENGINE_MINOR_VERSION > 18
	material->SetVectorParameterValueEditorOnly(FMaterialParameterInfo(paramName, EMaterialParameterAssociation::GlobalParameter), FLinearColor(r, g, b, alphaVal));
#else
	material->SetVectorParameterValueEditorOnly(paramName, FLinearColor(r, g, b, alphaVal));
#endif
}
void FRoadRunnerImportUtil :: SetColorParameter ( UMaterialInstanceConstant * material , const FName & paramName , const FString & colorString , float alphaVal ) { if ( colorString . IsEmpty ( ) ) { return ; } TArray < FString > colorStrings ; int numElements = colorString . ParseIntoArray ( colorStrings , TEXT ( " " ) , true ) ; if ( numElements != 3 ) { UE_LOG ( RoadRunnerImporter , Error , TEXT ( " " ) , * ( material -> GetFName ( ) . ToString ( ) ) , * ( paramName . ToString ( ) ) ) ; return ; } float r = FCString :: Atof ( * ( colorStrings [ 0 ] ) ) ; float g = FCString :: Atof ( * ( colorStrings [ 1 ] ) ) ; float b = FCString :: Atof ( * ( colorStrings [ 2 ] ) ) ; #if ENGINE_MINOR_VERSION > 18 material -> SetVectorParameterValueEditorOnly ( FMaterialParameterInfo ( paramName , EMaterialParameterAssociation :: GlobalParameter ) , FLinearColor ( r , g , b , alphaVal ) ) ; #else material -> SetVectorParameterValueEditorOnly ( paramName , FLinearColor ( r , g , b , alphaVal ) ) ; #endif }
Helper function to set color parameter in a material instance
Helper function to set color parameter in a material instance