I am just starting out on Unreal and C++, and am trying to expose to blueprints the UMaterial::GetUsedTextures function. My intent is to create a blueprint node that inputs a material and outputs a texture array.
I was following Rama’s documentation on this - but I just can’t seem to get it right.
I’ve created a blueprintfunction library, titled “GetUsedTextures” (Probably not the best idea to name my function library the same as the function I want to expose.)
Heres my code, if anyone could help me out that would be great! Thank you!
Working some more on it - believe I’ve made progress. Searching through the code I found PrimitiveComponent.h uses the same function I want to use. I copied its code but I’m still kicking up an error - I believe it has something to do with my UFunction.
Getting only one error now (yay). (:Error: TheFunctions.h(21) : Error: Cannot find class ‘’, to resolve delegate ‘Type’).
#include "UnrealVRTemplate.h"
#include "Materials/Material.h"
#include "TheFunctions.h"
void UTheFunctions::GetUsedTextures(TArray<UTexture*>& OutTextures, EMaterialQualityLevel::Type QualityLevel)
{
// Get the used materials so we can get their textures
TArray<UMaterialInterface*> UsedMaterials;
GetUsedMaterials(UsedMaterials);
TArray<UTexture*> UsedTextures;
for (int32 MatIndex = 0; MatIndex < UsedMaterials.Num(); ++MatIndex)
{
// Ensure we don't have any NULL elements.
if (UsedMaterials[MatIndex])
{
auto World = GetWorld();
UsedTextures.Reset();
UsedMaterials[MatIndex]->GetUsedTextures(UsedTextures, QualityLevel, false, World ? World->FeatureLevel : GMaxRHIFeatureLevel, false);
for (int32 TextureIndex = 0; TextureIndex<UsedTextures.Num(); TextureIndex++)
{
OutTextures.AddUnique(UsedTextures[TextureIndex]);
}
}
}
}