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"

Blueprint: Any way to set all materials?

Right now, we have objects with 4 or 5 materials. When we want to apply a "ghost" material to these objects, we currently need to override all the materials on the object with the "ghost" material.

What we'd really like is a way that we could use the "Set Material" action in the Blueprint graph to set them all.

This is especially true since our actor has about a dozen different components inside it, and setting 4 materials on each of 12 components gets out of hand fast.

Unfortunately, there doesn't seem to be a way to set the "Element Index" to something other than a single constant value, and it doesn't accept multiple "Make Literal Int" functions as inputs.

I've also tried making a custom "Set All Materials" function in Blueprint that will accept a PrimitiveComponent input and a MaterialInterface input, so I can replace all the "Set Material" actions with my custom function. It looks like this:

alt text

Unfortunately, I am seeing that the PrimitiveComponent input pin will only accept ONE input, meaning I can't connect all 12 of my components to this function the way I can with "Set Material."

There also seems to be a default "Target" input pin on this function when I place it, but trying to connect any of my components to it gives me the floating popup message "Object 'StaticMeshComponent' is not compatible with object 'self' "

Any ideas?

Product Version: Not Selected
Tags:
setallmaterials.png (188.5 kB)
more ▼

asked Mar 11 '14 at 05:23 AM in Everything Else

avatar image

ue4-archive ♦♦ STAFF
49.9k 3659 1983 9111

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

1 answer: sort voted first

I made this Blueprint setup for you. Hope it helps. :)

alt text

blueprintsetup.png (378.7 kB)
more ▼

answered Mar 11 '14 at 05:23 AM

avatar image

ue4-archive ♦♦ STAFF
49.9k 3659 1983 9111

avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 05:23 AM

Thanks, Satheesh -- That's very helpful!

I was able to get something like this working. However, I found it was problematic to put this in a Blueprint function since I needed this to be shared across many object types, and for various reasons I needed to put the function in a grandparent class which was non-blueprintable.

So I ended up doing it in code like so:

Header file:

 UFUNCTION( BlueprintCallable, Category=OurGame)
 void SetMaterialForAllComponents( UMaterialInterface * NewMaterial );

CPP file:

 void AOCBuildingTile::SetMaterialForAllComponents( UMaterialInterface * NewMaterial )
 {
     for( auto it = Components.CreateConstIterator(); it; ++it )
     {
         UStaticMeshComponent * pMeshComponent = Cast(*it);

         if ( pMeshComponent )
         {
             for ( int i = 0; i < pMeshComponent->GetNumMaterials(); ++i )
             {
                 pMeshComponent->SetMaterial( i, NewMaterial );
             }
         }
     }
 }
avatar image ue4-archive ♦♦ STAFF Mar 11 '14 at 05:23 AM

Another way to do it might be to use Material Parameter Collection and use those Params in all your materials.

avatar image plasmax Oct 11 '16 at 11:18 AM

This is excellent! I tweaked the setup slightly to first store all materials in an array and then swap them out all in the construction script, and then later I can access that array to reapply the original materials in the event graph. Thank you!

(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