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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

Using Arrays in Materials

Hey guys,

I try to export a Material I wrote in Unity to Unreal. Unfortunately I cannot find a way to loop through Arrays in Materials.

What I know so far:

  • I can create custom expressions to use a for-loop - Problem: There are no arrays which I can loop

  • There are Material Parameter Collection Assets, which store a Scalar and a Vector Array - Problem: I cannot get the Collection Arrays in the custom expressions. Its weird, because the generated HLSL code uses MaterialCollection0.Vectors[0]. But the Compiler doesnt recognize MaterialCollection0, when I try to apply the changes

  • I can use Textures to store data and loop through it - Problem: I tried to manipulate the data of a Texture2D and set a texture parameter value to it, but it didnt work. Maybe I overlooked something with this attempt.

It would be awesome if someone could help me with my problem :)

Thanks in advance for you answers

Greetings Cloudy

Product Version: UE 4.14
more ▼

asked Jan 26 '17 at 04:20 PM in Rendering

avatar image

Cloudy McStrife
465 13 15 38

avatar image Dunkelza Mar 21 '17 at 11:00 PM

I'm working on a similar issue, and it appears that we have to use a Blueprint instead of being able to do it just in the Material.

It would be really nice to be able to cycle through, say Emissive Color masks in the Material, though.

avatar image Cloudy McStrife Mar 23 '17 at 02:38 AM

I solved it with Material Parameter Collections. Actually they can only be read if at least one Parameter is set as an input for your custom expression. If you need further informations I can provide them

avatar image panha Mar 27 '17 at 06:42 PM

I have been trying to use array in material editor. Do you think I can populate my array via code ? or even more using user defined struct as an array?

avatar image Cloudy McStrife Mar 28 '17 at 11:09 AM

Unfortunately I didnt find a way to send custom structs to the shader. I used MaterialParameterCollection to send specific data via code to my Material.

To do this: 1. Create a MaterialParameterCollection Asset in the Unreal Editor 2. Add a specific number of elements to the Array (like 10, 20, 128, 256...) 3. Get this Asset in code by using ConstructorHelpers: static ConstructorHelpers::FObjectFinder MaterialParamCollection(TEXT("MaterialParameterCollection'/Game/Materials/EchoCollection.EchoCollection'"));

  1. Next is to fill the MaterialParameterCollection:

    FCollectionVectorParameter VectorParam; VectorParam.DefaultValue = FLinearColor(1, 0, 0);

    //Generate any Name to find this Parameter in you Collection FString Name = FString("Index_") + FString::FromInt(index) + FString("_"); VectorParam.ParameterName = *Name;

    // This line and the line below should not be different. I dont know anymore why I chose to do this twice :P. Maybe there is a difference ParameterCollection->VectorParameters[index++] = VectorParam;

    UKismetMaterialLibrary::SetVectorParameterValue(GetWorld(), ParameterCollection, VectorParam.ParameterName, VectorParam.DefaultValue);

    //The same procedure goes for FCollectionScalarParameter

To actually iterate through this array you have to write custom expression code in your materials

!!!Warning!!! You have to use one Vector or Scalar Parameter from the Collection as an Input. Otherwise the shader doesnt know your collection alt text

 for(int i = 0; i < NumberOfParams; ++i)
     float4 VectorParam = MaterialCollection0.Vectors[i];
     //Do something...

This should be it :)

avatar image bennetherwood May 28 '18 at 04:07 PM

Hi Cloudy McStrife,

Sorry, for unearthing this. Would you please be able to provide a HLSL code extract for accessing individual floats in an input float array? I am trying to do something with HLSL and the custom nodes, but its all new, and I cannot access individual array values properlly.

Cheers, Ben.

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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