Tuesday, October 2, 2012

Cookbook: UDK artist editable properties

Sooner or late in your development you'll come into phase when you have some game skeleton with a lot of parameters (camera, health, etc.). But how to tweak them without the necessity to update unrealscript (defaultproperties) and recompiling?

There are two approaches you can use. Let's take a closer look:

Instanced objects/actors

Each of your actors (buttons, movable/breakable objects, custom lights) will probably need some variables that are preferably tweakable by artist. Additionally each of there instances needs possibility to have differing values of parameters (imagine your ButtonActor with blue light and specific mesh vs other instance of ButtonActor with no light and different mesh).

This is easily achievable using named variables in unrealscript, syntax is really simple:

   1:  class ButtonActor extends Actor
   2:      ClassGroup(BallPuzzler)
   3:      placeable;
   5:  // /** */ specifies comment visible for artist in editor
   6:  /** enables actor movement upon activation */
   7:  //(Game) specifies category for parameter in unreal editor
   8:  var(Game) bool bMove;
  10:  /** movement offset from base position */
  11:  var(Game) vector vMoveOffset;
  13:  /** sound to play upon activation */
  14:  var (Game) SoundCue activationSound;
  16:  var(Light) const LightComponent    LightComponent;

This setup results in parameters being categorized in unreal editor into specified groups (F4 on selected actor):

I recommend to create archetype also for instanced objects to create subtypes (for example blue button, red button, healing button) and then use them to create instances (and edit few parameters per instance if necessary).

Not placeable objects

Ok, above mentioned steps work fine for instanced object that are being placed into game level. But what about objects without physical representation in editor (e.g. camera, controller, HUD, etc.)? Here we can create specific Properties object, that can be archetyped and it's parameters updated in content browser.

   1:  class BallPuzzlerProperties extends Object
   2:      HideCategories(Object);
   4:  /** min distance from camera */
   5:  var(Camera) vector CamOffsetNear;
   7:  /** max distance for camera */
   8:  var(Camera) vector CamOffsetFar;
  10:  /** focus inner radius when in exploration mode */
  11:  var(PostProcess)   float fFocusRadiusExploration;
  13:  /** movement speed */
  14:  var(Movement)   float Speed;
  16:  /** jump force */
  17:  var(Movement)   float Jump;
  19:  /** how much energy to drain at once */
  20:  var(Other)   float EnergyDrainAmount;
  22:  /** distance to moveable object allowing its pickup */
  23:  var(Manipulate)   float PickupDistance;

Creating and archetype is really simple. Open your Content Browser, click on Actor classes tab, uncheck all checkboxes (as this is not placeable, nor actor) and find your properties object. Right click, create an archetype, specify your package and some cool name (like Properties ;) ) and there you go! From now on, all your global parameters are accessible via properties of this archetype (F4)

To have an access to properties archetype in unrealscript, just reference it in variables and default properties. After that you can access it as any default structure.

   1:  class BallPuzzlerCamera extends Camera;
   3:  var const archetype BallPuzzlerProperties Properties; //declare variable
   5:  ...
   7:  //========================================================================
   8:  function ComputeCameraRotation(float DT)
   9:  {
  10:      local float partAngle;
  12:      //use it!
  13:      partAngle = Properties.CamRotDelta * DT;
  15:  ...
  17:  defaultproperties
  18:  {
  19:      //define it as external from package
  20:      Properties=BallPuzzlerProperties'BallPuzzlerGame.Archetypes.Properties'
  21:  }

No comments:

Post a Comment