x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Plugin - Get all materials in current project

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?

Product Version: UE 4.10
Tags:
more ▼

asked Dec 31 '15 at 10:47 AM in C++ Programming

avatar image

padmalcom
142 11 14 19

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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;
 }
more ▼

answered Jan 09 '16 at 10:52 PM

avatar image

padmalcom
142 11 14 19

avatar image mngpssn Feb 14 '17 at 12:16 AM

Is this possible to do with BP?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Dec 31 '15 at 12:55 PM

avatar image

TTaM
1.7k 81 28 81

avatar image padmalcom Dec 31 '15 at 01:47 PM

In the editor.

avatar image TTaM Dec 31 '15 at 05:36 PM

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.

avatar image padmalcom Dec 31 '15 at 05:38 PM

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.

avatar image TTaM Dec 31 '15 at 05:46 PM

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

avatar image padmalcom Jan 08 '16 at 01:15 PM

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?

avatar image TTaM Jan 08 '16 at 03:49 PM

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

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

avatar image TTaM Jan 08 '16 at 03:55 PM

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

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UObjectLibrary/CreateLibrary/index.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question