UDN
Search public documentation:

PhysicalMaterialProperty
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Physics > Physical Material Property

Physical Material Property


Overview


In UE3 you can attach a physical material to a Material or Material Instance Constant. Attaching, as opposed to just having a material with additional properties, allows for you to reuse your physical material property object on multiple materials.

A quick example would be the following: You have a gravel road material which you have applied to all of the gravel roads in the world. That gravel road material has a physical material called GravelPhysicalMaterial. In GravelPhysicalMaterial you have created a physical material property object, which stores the footstep sounds that is played when a pawn steps on the material.

Two physical materials on the same material are now supported on a single material. When a collision occurs the line check code finds the triangle hit, gets the texture UV at the hit location and looks up into a mask texture to determine if the hit pixel is black or white. The corresponding physical material will be returned. See the PhysicalMaterialMask page for more information.

Unrealscript Example


Look at PhysicalMaterial.uc

Specifically:

PhysicalMaterial.uc
var(PhysicalProperties) export editinline PhysicalMaterialPropertyBase PhysicalMaterialProperty;

PhysicalMaterialPropertyBase.uc has comments you will want to read!

To get contextual footstep sounds and lay the framework for having other neat PhysicalMaterial based effects you would make a subclass of PhysicalMaterialPropertyBase:

MyGamePhysicalMaterialProperty.uc
class MyGamePhysicalMaterialProperty extends PhysicalMaterialPropertyBase
  collapsecategories
  editinlinenew
  hidecategories(Object);

var(Sounds) const SoundCue FootStepSoundCue;

So now when a pawn steps (either through AnimNotify_Footstep or some other method) you can call PlayFootStepSound() which will then send that event to the correct pawn. Now that pawn can determine what sound to play based on the surface the pawn is walking on. e.g. A player is walking along the gravel road. When it steps and PlayFootStepSound() is called, trace down, find the physical material, get the stored SoundCue and play it.

Obviously with PhysicalMaterials and a framework of properties, like the above, you can do all kinds of really awesome contextual functionality (e.g. impact sounds, hit effects, decals, footsteps, etc.)

Hierarchy of Physical Materials.


Once your programming staff has created the specific game classes above, your content team can start making hierarchies of physical materials and start populating them with the effects that the game design demands.

Details for Content Creators

The PhysicalMaterial has a PhysicalMaterial Parent variable which allows you to create hierarchies of physical materials and thereby (in our example case) hierarchies of FootStep sounds. So you can have, Default -> Clay -> Wet Clay hierarchy as an example. So now your content team can be really specific in the physical materials they have in the game world. And when you want to have a Wet Clay footstep sound you can. If you don't have a Wet Clay footstep sound then you can look up the hierarchy until you find one or end up at the Default which should have a default footstep sound.

Using the Hierarchy

So now that you have both code support and a paramaterized physical material hierarchy, you can now assign physical materials to materials. Once you have assigned them you should hear them playing in the game.

Content Suggestions


When making footsteps (to continue our example) you should have your sound team make SoundCues with randomized footsteps in both the source sound and then the pitch and attenuation. This leads to a more believable foot step sound. Additionally it provides the correct abstraction to the physical material system.

Unreal Tournament 3 example


The way Unreal Tournament 3 implements their foot step sound system is that physical material properties store the type of surface instead of the sound cues associated with that material. From there, the UTPawn looks up the appropriate SoundCue to play that is stored within the SoundGroupClass.

UTPawn.uc
simulated function name GetMaterialBelowFeet()
{
  local vector HitLocation, HitNormal;
  local TraceHitInfo HitInfo;
  local UTPhysicalMaterialProperty PhysicalProperty;
  local actor HitActor;
  local float TraceDist;

  TraceDist = 1.5 * GetCollisionHeight();

  HitActor = Trace(HitLocation, HitNormal, Location - TraceDist*vect(0,0,1), Location, false,, HitInfo, TRACEFLAG_PhysicsVolumes);
  if ( WaterVolume(HitActor) != None )
  {
    return (Location.Z - HitLocation.Z < 0.33*TraceDist) ? 'Water' : 'ShallowWater';
  }
  if (HitInfo.PhysMaterial != None)
  {
    PhysicalProperty = UTPhysicalMaterialProperty(HitInfo.PhysMaterial.GetPhysicalMaterialProperty(class'UTPhysicalMaterialProperty'));
    if (PhysicalProperty != None)
    {
      return PhysicalProperty.MaterialType;
    }
  }
  return '';
}

simulated function ActuallyPlayFootstepSound(int FootDown)
{
  local SoundCue FootSound;

  FootSound = SoundGroupClass.static.GetFootstepSound(FootDown, GetMaterialBelowFeet());
  if (FootSound != None)
  {
    PlaySound(FootSound, false, true,,, true);
  }
}

simulated event PlayFootStepSound(int FootDown)
{
  local PlayerController PC;

  if ( !IsFirstPerson() )
  {
    ForEach LocalPlayerControllers(class'PlayerController', PC)
    {
      if ( (PC.ViewTarget != None) && (VSizeSq(PC.ViewTarget.Location - Location) < MaxFootstepDistSq) )
      {
        ActuallyPlayFootstepSound(FootDown);
        return;
      }
    }
  }
}