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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

how to use SetMaterial () to add multiple materials

hello I want to add several materials from the function SetMaterial()

 struct FConstructorStatics
     ConstructorHelpers::FObjectFinderOptional<UMaterial> MaterialNumbers;
         : MaterialNumbers(TEXT("/Game/Textures/dice_1_Mat.dice_1_Mat"))
 static FConstructorStatics ConstructorStatics;

 Box = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Box"));
 Box->SetMaterial(0, ConstructorStatics.MaterialNumbers.Get());

What I want is to add another material, for example, to MaterialNumbers

Box->SetMaterial(1, ConstructorStatics.MaterialNumbers.Get());

Product Version: UE 4.19
more ▼

asked Nov 04 '18 at 10:17 PM in C++ Programming

avatar image

61 2 5 9

avatar image Brian Johnstone Nov 05 '18 at 04:21 PM

Do you already have multiple materials created in the /Game/Textures folder and you just want to get them assigned to your Box? Since you hard-coded only a single reference to dice_1_mat the other material won't ever be found.

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

1 answer: sort voted first

Something like this?

 for(int i = 0; i < 100; i++)
     ConstructorHelpers::FObjectFinderOptional<UMaterial> MaterialNumber(*FString::Printf(TEXT("/Game/Textures/dice_%i_Mat.dice_%i_Mat"), i+1, i+1));
     Box->SetMaterial(i, MaterialNumber.Get());

I used 100 as the maximum number of possible materials. This could be any arbitrary number or it could be set as a parameter of the CDO.

more ▼

answered Nov 05 '18 at 08:49 PM

Brian Johnstone (suspended)
(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