Basic Iteration
This tutorial takes you through the process of building iterative procedures, that-is, repeatedly invoking a procedure to create more content.
Prerequisites
- This uses the Custom Asset tutorial, so please make sure you are using a project where you've already followed that tutorial.
Primary Goals
- Basic iteration
- Recursively invoking a procedure from itself
- Testing the end condition
- Accumulating all the generated content
Secondary Goals
- Parameterisation by quantity
- Using Notes to group and document procedures
- Using Comments to explain operator use
- Groundwork for the following demo
Instructions
Create the procedure
- Open the Apparance Editor and create a new procedure
Test.Block Stack
(Named Block Stack and in the Test category). - Add the
Shiny Cube
procedure to your new procedure (as you would any other operator, but dragged from the Procedure panel instead). - Use it's Where? input as the first procedure input (drag out to the left side).
- Add an integer greater-than operator (
GreaterThanI
) connected to an If operator for switching content (IfSeg
). - Add a Merge operator (
Merge2
) to accumulate the current block into the generated stack. - Add a frame offset operator (
Offset
) to place each new block on top of the previous one (Z shift by 1x the current block size) - Add an integer subtract (
SubI
) to reduce the count each iteration. - Wire everything up as shown below, taking the output of the If as the only procedure output and the Cube/Offset frame and GT/sub integer inputs as the inputs (Cube and Count respectively).
- Now comes the fun part; drag the
Shiny Cube
procedure from the Procedure panel and place it inside itself. Wiring up as shown. - Configure the Count input to acept a range of values:
- Select the Count input to access it's properties.
- Click the
Metadata
button next to the description field. - In the expanded UI you can now configure its editing behaviour.
- Click the Ranged checkbox, leave the default min/max at 0 and 100 for now.
- Save the procedure by clicking the Save button or Ctrl+S.
Content is passed around in Apparance using a data type called
Model Segment
as it refers to a specific part of the accumulated content or geometry built so far. Generally you can just treat this as a 'content pipe' that feeds the overall procedure output. It is represented in the Apparance Editor with white wiresPlace the procedure
- Back in Unreal, drag in a new Apparance Entity and set it to use the
Test.Block Stack
procedure. - Set the Cube parameter size to 1 x 1 x 0.1 (to squash it)
- Dial up the Count parameter to create your block stack
Extras
Optionally you can document the procedure a little by:
- Grouping the recursive part of the graph with a Note.
- Marquee select the three operators with LMBdrag.
- Group together using Group with note in the RMBcontext menu.
- Resize/rearrange the note by LMBdouble-clicking on it.
- Change the note text by LMBdouble-clicking on it a second time. (click off it to finish).
- Adding a comment to the greater-than operator to explain what it is doing:
- Select the
>
operator - In the property panel notice the faint 'Comment' field at the top, below the description and above the input list.
- Enter a comment such as "are there any more?"
- The property appears normal and the comment text now appears above the operator in the node graph.
- Select the
Procedure
Your procedure should look something like this:
Next Steps
This tutorial has set the groundwork for the following Introducing Variation tutorial that you may want to follow next.