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"

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

How can I assign a material to all LODs?

Hello,

I wrote the following function for the constructor of my StaticMesh class to assign a material instance (of the already assigned material) to the model which can be tinted with any color:

 void ASomPickup::UpdateMaterials()
 {
 
     //Get Original Material
     if (Pickup_Material_Origin == NULL && !EnvironmentMesh->GetMaterial(0)->IsA(UMaterialInstanceDynamic::StaticClass()))
         Pickup_Material_Origin = EnvironmentMesh->GetMaterial(0);
 
 
     //Get and assign Material Instance
     if (Pickup_Material_Origin != NULL)
     {
         if (Pickup_Material == NULL)
         {
             Pickup_Material = UMaterialInstanceDynamic::Create(Pickup_Material_Origin, this);
             Pickup_Material->SetVectorParameterValue(FName(TEXT("Tint")), ColorTint);
 
         }
 
         TArray<UMaterialInterface*> CompMats;
 
         if (EnvironmentMeshComponent != NULL)
         {
             CompMats = EnvironmentMeshComponent->GetMaterials();
 
             for (int32 iMats = 0; iMats < CompMats.Num(); iMats++)
             {
                 EnvironmentMeshComponent->SetMaterial(iMats, Pickup_Material);
             }
         }
     }
 
 }

Now the problem is that the tint only seems to have effect on the highest/"nearest" LOD of the model (LOD 0). It seems that the lower LODs don't have the new instanced material assigned to them.

alt text

Any help is appreciated.

Product Version: UE 4.7
Tags:
shirtlods.jpg (51.0 kB)
more ▼

asked May 23 '15 at 01:30 PM in C++ Programming

avatar image

Pseudocorpus
421 37 47 143

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

1 answer: sort voted first

It seems this guy had the same question and got it resolved. Check it out. It's blueprint but you can easily trnsfer the logic to C++

https://answers.unrealengine.com/questions/152014/how-do-i-set-a-dynamic-material-instance-on-all-lo.html

more ▼

answered May 23 '15 at 01:36 PM

avatar image

maparizeau
105 7 7 14

avatar image Pseudocorpus May 23 '15 at 02:25 PM

Thanks maparizeau! Your answer pushed me to the right direction.

In line 23 I checked for the Number of elements on the StaticMeshComponent:

 CompMats = EnvironmentMeshComponent->GetMaterials();

I logged it, and it did spit out "1". That obvioiusly couldn't be right, since I have multiple LODs. Instead I should have checked for the Number of material elements on the Mesh of the StaticMeshComponent:

 CompMats = EnvironmentMeshComponent->StaticMesh->Materials;

Now it seems to work perfectly. Thanks again!

avatar image maparizeau May 23 '15 at 02:26 PM

my pleasure and happy game deving ;)

(comments are locked)
10|2000 characters needed characters left
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