Agrarsense
MaterialParameterCollectionUtilities.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
7
8#include "Materials/MaterialParameterCollection.h"
9#include "Kismet/GameplayStatics.h"
10#include "Engine/Engine.h"
11#include "Engine/World.h"
12
13bool UMaterialParameterCollectionUtilities::UpdateMaterialCollectionVectorValue(UMaterialParameterCollectionInstance* MPCInstance, const FName ParameterName, const FVector4 Value)
14{
15 if (MPCInstance)
16 {
17 return MPCInstance->SetVectorParameterValue(ParameterName, Value);
18 }
19
20 return false;
21}
22
23bool UMaterialParameterCollectionUtilities::UpdateMaterialCollectionScalarValue(UMaterialParameterCollectionInstance* MPCInstance, const FName ParameterName, const float Value)
24{
25 if (MPCInstance)
26 {
27 return MPCInstance->SetScalarParameterValue(ParameterName, Value);
28 }
29
30 return false;
31}
32
33UMaterialParameterCollectionInstance* UMaterialParameterCollectionUtilities::LoadMaterialParameterCollectionInstance(const UObject* WorldContextObject, const FString& Path)
34{
35 if (!WorldContextObject || !GEngine)
36 {
37 return nullptr;
38 }
39
40 UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
41 UMaterialParameterCollection* Collection = LoadObject<UMaterialParameterCollection>(nullptr, *Path);
42 if (Collection && World)
43 {
44 return World->GetParameterCollectionInstance(Collection);
45 }
46
47 return nullptr;
48}
static bool UpdateMaterialCollectionVectorValue(UMaterialParameterCollectionInstance *MPCInstance, const FName ParameterName, const FVector4 Value)
static UMaterialParameterCollectionInstance * LoadMaterialParameterCollectionInstance(const UObject *WorldContextObject, const FString &Path)
static bool UpdateMaterialCollectionScalarValue(UMaterialParameterCollectionInstance *MPCInstance, const FName ParameterName, const float Value)