Changing Textures with Kismet
From RoboBlitz Editor Wiki
Contents |
Introduction
This tutorial will cover how to set up a Material, Material Instance, and the Kismet code needed to change a texture on the fly.
Material Setup
Select a texture and add it to the material as a TextureSampleParameter2D (TSP2D). Since the TSP2D can only be hooked up to the diffuse slot I added a multiply so I could add it to the emissive slot as well. The most important part of the TSP2D is the ParameterName since this will be used by the MaterialInstance and Kismet.
MaterialInstance Setup
- Right click in the generic browser and choose "New MaterialInstanceConstant"
- In the window that pops up give the new MaterialInstance a name and hit "OK"
- A window for the properties of the MaterialInstance will pop up now. Note: You can bring this window up again by right clicking the MaterialInstance and selecting "Properties"
- Add the Material you made in to the Parent slot
- Click on "TextureParameterValues" and press the plus sign to add a slot (slot 0)
- Use the same "ParameterName" as the one you used for the TSP2D in the Material. This set is very important!
- Add a texture to the "ParameterValue". Usually the same one from the Material, but it could be a different one if you want. This will be the default texture when applying it to your static mesh.
- Select the static mesh you wish to apply the MaterialInstance to and open the static mesh editor. Add it to one of the LODInfo > [0] > Elements slots. Or apply the MaterialInstance to a BSP surface.
Kismet Code
I'm just going to make a simple kismet loop that switches the texture after a delay. You can apply the other kismet tutorials to this to change the texture after the player actives a trigger or whenever you want.
- Add an event. I'm using Event > Level Loaded and Visible
- Add an Action > Material Instance > Set TextureParam.
- Link the Out from the event to the In of the Set Texture Param.
- Select your MaterialInstance in the generic browser and add it to the MatInst slot
- Select the Texture you wish to use and add it to the "NewTexture" slot
- Add the proper name to the "ParamName" slot. The same name used in the TSP2d and MaterialInstance TextureParameterValue
- Add a delay and give it a Duration. New Action > Misc > Delay. (Note: Timer does not work)
- Link the "Out" of the Set TextureParam to the "Start" of the Delay
- Copy and paste your Set TextureParam and give the copy a different "NewTexture"
- Link the "Finished" of the Delay to the "In" of the new Set TextureParam
- Copy and Paste your Delay and link the "Out" of the second Set TextureParam" to the "Start" of the second delay. Link the "Finished" of the second delay to the "In" of the first Set TextureParam
You should now have a infinte loop with the texture swaping every X seconds based on the durations of your delays.
More Complex Kismet Example
The image below shows the kismet code I setup for a traffic light cycle in my map. There are dynamic lights that change along with the textures.





