I remember struggling with this very issue in my early days of Unrealscript learning too, as alot of the UDN pages assume a certain level of scripting knowledge (and the weird, half-finished sentences and broken English certainly don’t help).
First of all, you’ll want to create global variables of the HitMaskComponent and a TextureRender2D, so you can reference them later in your code:
var() const SceneCapture2DHitMaskComponent HitMaskComponent;
var TextureRenderTarget2D MaskTexture;
Then create the actual Hitmaskcomponent in your default properties:
// Add hit mask to the actor
Begin Object Class=SceneCapture2DHitMaskComponent Name=HitMaskComp
FadingStartTimeSinceHit = 9.0
FadingIntervalTime = 0.35
FadingDurationTime = 8.0
FadingPercentage = 0.96
End Object
HitMaskComponent=HitMaskComp
Components.Add(HitMaskComp)
Then, ideally in a function that is called when the pawn spawns ( I put this in SetCharacterClassFromInfo() ), you need to create the texture target we made a global variable for, which the Hitmask will use when drawing, and feed that into the Hitmaskcomponent so it knows exactly how to draw the Hitmask texture:
// Create Mask Texture of 64x64(or whatever size you'd like)
MaskTexture = class'TextureRenderTarget2D'.static.Create(64, 64, PF_G8, MakeLinearColor(0, 0, 0, 1));
if ( MaskTexture!=none )
{
// Update HitMaskComponent with this texture
HitMaskComponent.SetCaptureTargetTexture( MaskTexture );
}
As for the material itself, create the appropriate nodes as explained on the UDN page. Then create a ‘Lerp’ Node, and plug the ‘FilterMask’ Node into the ‘Alpha’ input. Plug your base texture into the ‘A’ input, and whatever gore texture you want to be ‘revealed’ by the Hitmask into ‘B’ input. This is the main advantage of Hitmasks over decals - you could, for example, create a Terminator-style enemy that has a circuitry/metallic skeleton texture as the ‘B’ input and have that be exposed by the Hitmask whenever you damage it.
Next, you need to create a MaterialInstanceConstant for your base material, and feed the Filtermask parameter the MaskTexture info:
local MaterialInstanceConstant MIC;
MIC = Mesh.CreateAndSetMaterialInstanceConstant(0); // material you'd like to replace
if ( MIC != none && MaskTexture!=none )
{
// Set new texture as FilterMask parameter
MIC.SetTextureParameterValue('FilterMask', MaskTexture);
}
Once this has all been set up, you just need to call the code which actually creates the Hitmask, in TakeDamage or wherever is most appropriate for you:
HitMaskComponent.SetCaptureParameters(HitLocation, 20.f, HitLocation, FALSE);
It’s worth noting that the quality of the resulting hitmask is largely dependent on how well you have set up your character’s UVs; if you’re just using a basic prototype material for your characters then the hitmask will look very ugly or not work at all. In that case, it would be better to simply apply a blood decal.