Toggling Materials through Kismet

Quite often you will want to adjust lights in the scene to turn them on and off according to events that happen during gameplay. Now we'll look at how to convert a lamp mesh so it has a Material with an Emissive feature and an alternative Material with no Emissive feature. This will help create the illusion of a lamp being turned on and off. This will be followed by a lesson on how to toggle a PointLight in the scene to continue to set up of that illusion. We're dealing with a lamp mesh as the source of illumination, and that requires a Material to be swapped for an on and off variant, so we'll look at the use of the Set Material action in Kismet.

Getting ready

The scene we'll work with would take a while to set up, so a starting point has been provided. From the provided content, load the map Packt_04_SetMaterial_Start.UDK. The scene includes at one end of a passage two switch elements and some lamp meshes. The lamps have a Material with a flickering Emissive channel. This is what needs to be turned off when the lamp is switched off.

How to do it...

  1. There are two things to consider with the toggled lights: one is the light cast from it, and the other is the texture showing on it. The lamp mesh, which has a Material for "lights on" also needs a replacement Material for "lights out". We will create a Set Material action in Kismet.
  2. If you can't spot it, select the lamp mesh InterpActor_7 using the Edit | Find Actor menu. Press either the Go To text button in the floating window or the toolbar icon Go to Actor [ How to do it... ], or Home.
    How to do it...
  3. Right-click and choose Materials | Find in Browser or press Ctrl + Shift + B.
  4. The Material HU_Mech.Material.M_HU_Mech_SM_Light01 should now be highlighted in the Content Browser. Right-click on it and choose Create a Copy, and set a copy to your own package and rename it Yourfolder.Material.LampOff.
  5. Double-click the result and the Material Editor will open. Here, simply press ALT + LMB on the wire feeding into the Material's Emissive channel to disconnect it. Then press the green tick [ How to do it... ] in the top corner of the Material Editor to compile the change, and close. Right-click on the changed Material asset in the Content Browser and choose Save.
    How to do it...
  6. Make sure that your new LampOff Material is highlighted in the Content Browser and right-click on the lamp mesh and choose Material | Assign from Content Browser. Also, right-click on the lamp mesh in the scene, and choose Convert | Convert StaticMeshActor to Mover. This is so it can be accessed in Kismet.
  7. Still in the Content Browser, filter Materials, then search for LampOff.
  8. In Kismet, right-click and choose New Action | Actor | Set Material.
  9. In this action's properties, expand Seq Act_Set Material. In the channel New Material we'll assign the Material M_HU_Mech_SM_Light01 from the Content Browser. Tick the assign icon [ How to do it... ] to assign M_HU_Mech_SM_Light01.
  10. With the lamp mesh selected in the scene, right-click on the Target nub of the Set Material action, and choose New Object Var using InterpActor.
  11. Now Alt-drag the mesh across the wall so a copy sits opposite the first.

    Tip

    Notice the name of the copy is the same as the old version. The old version gets renamed, which is recursive and something that can take some getting used to. Any references to the old object will be updated automatically to reflect the name change.

  12. In Kismet, select the Set Material action from before, and copy and paste it using Ctrl + C and Ctrl + V. You may have to Alt + Left-click on the Target nub to break the link to the original variable. Assign the second lamp mesh to this Set Material action.
    How to do it...
  13. Connect each Set Material to the relevant Trigger event's Used nub, as in the previous screenshot. Remember that in your network other wires will be connected to the events too. If you want to duplicate the events to space things out and keep things clean that is fine, but usually it is best to make the most use of a single node where possible. Using duplicate nodes can make later editing harder.
  14. Build again and PIE to see if the Material is being swapped from unlit to lit on the lamp when you trigger each switch. Make sure the left switch fires the left lamp, and the right switch fires the right lamp. An example is provided in the scene Packt_04_SetMaterial_DEMO.UDK.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.74.44