UDN
Search public documentation:

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

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 > Unreal Development Kit Gems > Creating a For Loop Kismet node
UE3 Home > Kismet Visual Scripting > Creating a For Loop Kismet node

Creating a For Loop Kismet node


Last tested against UDK Apr, 2011
PC and iOS compatible

Overview


It is useful sometimes to be able to loop sections of Kismet; quickly and easily.

Unrealscript


This Kismet nodes works by continuing to activate connected Kismet nodes until it's internal count reaches the end. The loop is still achieved with Kismet. It is still flexible enough to allow you add other Kismet based conditions to stop or pause the loop.

SeqAct_ForLoop.uc
class SeqAct_ForLoop extends SequenceAction;

// The number to use as the start of the loop
var() int Start;
// The number to use as the end of the loop
var() int End;
// How much to increment the for loop by. Always use a positive number
var() int Increment;
// Include end when iterating
var() bool IncludeEnd;
// Index output in case it is useful for level designers
var int Index;
// Internal index
var int InternalIndex;
// Has the internal index been set before?
var bool HasSetInternalIndex;

event Activated()
{
  // Check if we have a range to iterate over
  if (Start == End || Increment <= 0)
  {
    return;
  }

  if (!HasSetInternalIndex)
  {
    InternalIndex = Start;
    HasSetInternalIndex = true;
  }

  if (Start < End)
  {
    Index = InternalIndex;

    if (InternalIndex < End || (IncludeEnd && InternalIndex <= End))
    {
      ActivateOutputLink(0);
      InternalIndex += Increment;
    }
    else
    {
      InternalIndex = Start;
    }
  }
  else if (Start > End)
  {      
    Index = InternalIndex;

    if (InternalIndex > End || (IncludeEnd && InternalIndex >= End))
    {
      ActivateOutputLink(0);
      InternalIndex -= Increment;
    }
    else
    {
      InternalIndex = Start;
    }
  }
}

defaultproperties
{
  Increment=1
  InternalIndex=0
  bAutoActivateOutputLinks=false
  HasSetInternalIndex=false
  ObjName="For Loop"
  ObjCategory="Misc"
  InputLinks(0)=(LinkDesc="In")
  OutputLinks(0)=(LinkDesc="Out")
  VariableLinks.Empty
  VariableLinks(0)=(ExpectedType=class'SeqVar_Int',LinkDesc="Start",PropertyName=Start)
  VariableLinks(1)=(ExpectedType=class'SeqVar_Int',LinkDesc="End",PropertyName=End)
  VariableLinks(2)=(ExpectedType=class'SeqVar_Int',LinkDesc="Increment",bHidden=true,PropertyName=Increment)
  VariableLinks(3)=(ExpectedType=class'SeqVar_Int',LinkDesc="Index",bWriteable=true,PropertyName=Index)
}

How to use


The way to use this node is to specify the Start and End numbers you wish the for loop to increment between. If you wanted to go from 1 to 6 for example, you would set the Start to 1 and the End to 7 (or 6 and checking the IncludeEnd variable). You can also alter the increment steps, by increasing or decreasing the Increment value. This would allow you to go from 0 to 16 in the pattern of 0, 2, 4, 6, ... if you set Increment to 2.

You can also set a delay before you loop the Kismet. This would mean that between each step there would be a pause. In the example below, I've set a delay of 1 second between each iteration.

You can also retrieve the current for loop index by connecting the Index parameter to an Int variable. In the example below, I also convert it to a string which I then output into the log for testing purposes.

KismetForLoop.jpg

Related topics