I don't need to test my programs. I have an error-correcting modem.

User:00zX/Using The Unreal Engine 3 Preprocessor

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Including Macro Files

class YourPawn extends UTPawn
	config(YourConfig);
 
`include(YourMacroFile.uci)

Example Macro File

When compiling with the -debug command line switch, the debug macro will then be defined and will switch our blank spaces to config/exec respectively.

`if(`notdefined(Debug))
 `define dconf
 `define dexec
`else
 `define dconf config
 `define dexec exec
`endif

Copy the above template into a blank text document and call the file YourMacroFile.uci

Example of usage

If we want to add a variable thats configurable only when the macro `DevBuild is defined.

class YourPawn extends UTPawn
	config(YourConfig);
 
`include(YourMacroFile.uci)
 
var `{dconf} bool	bCanDodge;
 
function bool Dodge(eDoubleClickDir DoubleClickMove)
{
	if(bCanDodge)
		return Super.Dodge(DoubleClickMove);
	else
		return false;
}
 
defaultproperties
{
`if(`notdefined(Debug))
	bCanDodge=True
`endif
}

YourConfig

[YourPackage.YourPawn]
bCanDodge=True

Example of usage

If we want to add a variable that already exists but is not config editable. (PostBeginPlay)

class YourPawn extends UTPawn
	config(YourConfig);
 
`include(YourMacroFile.uci)
 
`if(`isdefined(Debug))
var `{dconf} float	newGroundSpeed;
 
function PossessedBy(Controller C, bool bVehicleTransition)
{
	Super.PossessedBy(C, bVehicleTransition);
 
	GroundSpeed = newGroundSpeed;
}
`endif

Useful Macros

/**
 * 2005-2011 Daniel Batten (aka 00zX or MonsOlympus)
 */
 
/** UDK HELPERS */
 
	/*`define redef(OldDef, NewDef) `undefine `{OldDef} `define `{OldDef} `{NewDef}*/
 
	/* Globals */
	`define sWorld_Info class'WorldInfo'.static.GetWorldInfo()
	`define sGame_RepInfo `{sWorldInfo}.GRI
	`define sGravity `{sWorldInfo}.WorldGravityZ
	`define sEngine class'Engine'.static
 
 
	/** Timers - checks the timers to see if they are active before setting or clearing them. */
	`define CheckClearTimer(name) if(IsTimerActive(nameof(`name))){ClearTimer(nameof(`name));}
	`define CheckSetTimer(time, loop, name) if(!IsTimerActive(nameof(`name))){SetTimer(`time, `loop, nameof(`name));}
	`define ResetTimer(time, loop, name) SetTimer(`time, `loop, nameof(`name))
 
	/** Variables and Defaults */
	`define SetToDefault(Obj, Var) `{Obj}.`{Var} = `{Obj}.Default.`{Var}
	`define SetVar(Obj, Var) `{Obj}.`{Var} = `{Var}
           //Usage: `SetVar(`P, MaxMultiJump) ~ where `P is UTPawn(Pawn) cast.
           //Outputs: UTPawn(Pawn).MaxMultiJump = MaxMultiJump; ~ Where UT Prefix can be a macro also.
 
	`define CheckRet(Obj) if(`Obj == none) return
 
	/** Save/Load Object */
	`define SaveObj(Obj, FileName, Bool, Ver) `sEngine().BasicSaveObject(`{Obj}, `{FileName}, `{Bool}, `{Ver})
	`define LoadObj(Obj, FileName, Bool, Ver) `sEngine().BasicSaveObject(`{Obj}, `{FileName}, `{Bool}, `{Ver})
 
	/** MetaTags */
	`define mUI(min, max) <UIMin=`min | UIMax=`max>
	`define mClamp(min, max) <ClampMin=`min | ClampMax=`max>
	`define mUIClamp(min, max) <UIMin=`min | UIMax=`max | ClampMin=`min | ClampMax=`max>
 
	/* Debugging */
	`define LogName 'Debug'
	`define LogdLine() `logd("------------------------------------------------------",,`{LogName});
	`define LogFunc(Name) `log(Self$"."$class.name$"."$GetFuncName()$"()",,`Name);
	`define LogdFunc() `logd(Self$"."$class.name$"."$GetFuncName()$"()",,`{LogName});
	`define LogF(string) `logd(GetFuncName()$"(): "$`{string},,`{LogName});
 
	/* Pawn */
	`define ColHeight CylinderComponent.CollisionHeight
	`define ColRadius CylinderComponent.CollisionRadius
	`define DefColHeight CylinderComponent.Default.CollisionHeight
	`define DefColRadius CylinderComponent.Default.CollisionRadius