# Plugin - Get all materials in current project

**URL:** <https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793>\
**Category:** Plugins\
**Tags:** unreal-engine, Plugins, CPP, question\
**Created:** [December 31, 2015, 10:47am UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793 "2015-12-31T10:47:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![padmalcom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@padmalcom](https://forums.unrealengine.com/u/padmalcom)\
**Post date:** [December 31, 2015, 10:47am UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/1 "2015-12-31T10:47:27Z")

</div>

Hi, I want to offer my users to pick a material from a dropdown list OR let them assign a material from the content browser. To both requirements I cannot find any solution (Neither to finding all materials in my project or just in one folder nor to display a material field in my plugin).

Can you give me any hint on how to do this?

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 31, 2015, 12:55pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/2 "2015-12-31T12:55:07Z")

</div>

Do you want them to do this in the editor? Or in your game?

---

<div class="post-metadata">

**Author:** ![padmalcom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@padmalcom](https://forums.unrealengine.com/u/padmalcom)\
**Post date:** [December 31, 2015, 1:47pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/3 "2015-12-31T13:47:03Z")

</div>

In the editor.

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 31, 2015, 5:36pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/4 "2015-12-31T17:36:22Z")

</div>

Simply creating a property on a struct/class will allow the user to select the assets available in your project. For materials, use MaterialInterface, not Material.

In c++, you’ll need to make it a UPROPERTY with the ‘EditAnywhere’ flag.

---

<div class="post-metadata">

**Author:** ![padmalcom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@padmalcom](https://forums.unrealengine.com/u/padmalcom)\
**Post date:** [December 31, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/5 "2015-12-31T17:38:04Z")

</div>

Hi TTaM, thanks for your answer. Unfortunately I cannot use UPROPERTY in a plugin tab in Slate. For an actor sure, I’d simple chose a UPROPERTY to edit a material.

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [December 31, 2015, 5:46pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/6 "2015-12-31T17:46:12Z")

</div>

Slate? Oh, well, I’ll leave that to the experts.

---

<div class="post-metadata">

**Author:** ![padmalcom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@padmalcom](https://forums.unrealengine.com/u/padmalcom)\
**Post date:** [January 8, 2016, 1:15pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/7 "2016-01-08T13:15:45Z")

</div>

push, any ideas? I don’t care if I show the materials just by names in a drop down or in an image in my slate widget. My problem is that I do not know how to determine all materials from the project in a widget. There must be some easy to use kind of function for that case, right?

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [January 8, 2016, 3:49pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/8 "2016-01-08T15:49:20Z")

</div>

Oh yes, I remember now. You can do this…

GetObjectsOfClass( UMaterialInterface::StaticClass(), … );

---

<div class="post-metadata">

**Author:** ![Daekesh](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/daekesh/32/918652_2.png) [@Daekesh](https://forums.unrealengine.com/u/Daekesh)\
**Post date:** [January 8, 2016, 3:55pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/9 "2016-01-08T15:55:13Z")

</div>

You might also need to use a UObjectLibrary to load all the materials, if they aren’t loaded automatically.

> **[UObjectLibrary::CreateLibrary](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Engine/UObjectLibrary/CreateLibrary/)**
>
> Static function to create a new ObjectLibrary at runtime, with various options set There is now a better version of this functionality in AssetManager, if you are creating many game-specific libraries you should switch to using AssetManager instead

---

<div class="post-metadata">

**Author:** ![padmalcom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@padmalcom](https://forums.unrealengine.com/u/padmalcom)\
**Post date:** [January 9, 2016, 10:52pm UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/10 "2016-01-09T22:52:27Z")

</div>

TTaM, you are great! With your help I managed to write a function to get all materials from the editor.

```
TArray<UMaterialInstance*>* RoadNetworkWidget::getMaterialInstancesFromPath(FString _path) {

	TArray<UMaterialInstance*>* result = new TArray<UMaterialInstance*>();

	UObjectLibrary *lib = UObjectLibrary::CreateLibrary(UMaterialInstance::StaticClass(), false, true);
	UE_LOG(LogTemp, Warning, TEXT("Searching for material instances in /Game/Materials..."));
	lib->LoadAssetDataFromPath(TEXT("/Game/Materials"));
	TArray<FAssetData> assetData;
	lib->GetAssetDataList(assetData);
	UE_LOG(LogTemp, Warning, TEXT("Found %d"), assetData.Num());

	for (FAssetData asset : assetData) {
		UMaterialInstance* mi = Cast<UMaterialInstance>(asset.GetAsset());
		if (mi) {
			UE_LOG(LogTemp, Warning, TEXT("Material instance %s"), *mi->GetName());
			result->Add(mi);
		}
	}
	return result;
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_cbf8aac6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_cbf8aac6](https://forums.unrealengine.com/u/anonymous_user_cbf8aac6)\
**Post date:** [February 14, 2017, 12:16am UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/11 "2017-02-14T00:16:49Z")

</div>

Is this possible to do with BP?

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [March 21, 2018, 10:01am UTC](https://forums.unrealengine.com/t/plugin-get-all-materials-in-current-project/342793/12 "2018-03-21T10:01:13Z")

</div>

Yes it is: [http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UObjectLibrary/LoadBlueprintAssetDataFromPaths/index.html](http://api.unrealengine.com/INT/API/Runtime/Engine/Engine/UObjectLibrary/LoadBlueprintAssetDataFromPaths/index.html)
