From within the level blueprint, I am spawning a particle system to a target point following a 10-second delay. What I would also like to do is assign a material to an actor at the same 10-second interval. Not sure how to do this.
It looks like you need to use a small custom event. You can use this method for both Materials and Material Instances, and I’ve uploaded a screenshot to show you how to do it, although I haven’t used a Level Blueprint.
Some explanations for a better understanding of the process:
- Use an array (= a collection of multiple variables/ values) to store your Materials, instead of a single variable. I’ve highlighted on the first screenshot how to create an array instead of a single variable (just create a variable and transform it into an array with the small icon near the variable type)
- The variable type to store material(s) is a Material Interface (see Screenshot 2). Use an Object Reference (because it actually refers to an existing asset (object) in your world, while a class reference would be useful if you spawn something for the first time)
- An array is an ordered list of values or elements (here, of Materials). To access an array value, you need to know its index, and the first item on the array has the index of 0.
- The Element index on the Set Material node specify what material will be changed on your mesh. It’s useful if you have multiple materials for the same mesh and want to change a specific material.
- To create the “Get” node, just drag from your Material Array pin, and select get (a copy)
Hope it helps
Wow, excellent! Thanks GoldenYoann3D! I’ll give it a try!
The “set material” node works for static meshes, but it refuses to be set to an actor.
I understand, here’s some screenshots showing how to achieve the same result with an actor in Blueprints. Now, there are 3 case scenarios I can think of on how to achieve that:
- Setting the actor in a predefined public (exposed) variable.
- Spawning the actor (from BeginPlay, for example) & set it as a variable
- Getting all Actors from Class, in case you don’t set it as a variable in advance ( The “Get All Actors of Class” node is really heavy since it loops through all Actors in a scene, and not very optimized for most cases. Use it with caution)
Some precisions on these different ways:
- The variable I used is the specific Actor class (Object Reference) I have created in my project (the one that will change its material). In other words, the variable refers to a specific Actor Blueprint Class in the project/ Content Folder (CubeActor in my case), and not to a generic Actor.
If it’s a Level Blueprint, you can directly set the variable value from the Default Value parameter in the Detail Panel, when you click on that variable (see the red line in Screenshot 1).
If it’s a Blueprint placed in your map, then you have to expose it/ make it public (by opening the small eye near the Variable name or by checking “Instance Editable” from the Detail Panel, see the blue marks in Screenshot 1) and set it from the Editor.
- Plug your specific exposed Actor variable (highlighted in Screenshot 1) to the target pin in the Set Material node to automatically convert it.
Hope it helps
Screenshot 1 - Public Variable
Screenshot 2 - Spawning
Screenshot 3 - Get All Actors from Class
This works like a charm, it’s exactly what I was looking for. What I’m struggling to figure out however is how to change the materials in their correct order instead of randomly. Is this something you can help with?