Language:
Page Info
Tags:
Skill Level:
Engine Version:

3 - Performing an Intersection of Blueprint Sets

Choose your OS:

By now, you should have a TextRender Actor displaying the contents of a Blueprint Set that you defined in the previous step. In this step, you're going to learn how to perform an Intersection of two Blueprint Sets, ultimately printing the result of the Intersection in the game's Viewport.

  1. From your project's Content Browser, double-click the Display Set TextRender Actor to open its Blueprint Event Graph.

    Click for full image.

  2. You should see the Display Set TextRender Actor Blueprint Event Graph, where you'll be able to add a new Blueprint Set to Intersect with the existing Instruction Set, ultimately displaying a resultant Set to the Viewport.

    Click for full image.

  3. At this point in the tutorial, you'll want to create a couple of Blueprint Set containers for the upcoming Intersection. Go ahead and right-click on the Instruction Set variable and select Duplicate from the drop-down list to create two new Blueprint Set variables, naming them Shorter Instruction Set and Resultant Instruction Set.

    Step3_3.png

    Performing an Intersection on two Sets (typically) involves a Resultant Set, which will contain only those items that are common to both Sets

  4. You should now have two new Blueprint Set variables, which you duplicated from the existing Instruction Set variable. You should also notice that if you select one of your new Blueprint Sets (for example, Resultant Instruction Set), the Default Value message, saying Please compile the blueprint, should be visible.

    Click for full image.

  5. Go ahead and click the Compile button.

    Click for full image.

  6. After compiling your Blueprint, you should see the Default Value message disappear, making way for some existing elements. As you know, you performed a duplication of the existing Instruction Set variable to create two new variables, thereby duplicating the elements that were originally contained in the original Blueprint Set into the newly created containers.

    Step3_6.png

    Please note that you can create new variables without having to duplicate existing variables.

  7. To clear the Resultant Instruction Set, go ahead and click the Removes all items button located in the Default Value menu.

    Click for full image.

  8. Now, clear the items (or elements) from the Shorter Instruction Set.

    Click for full image.

  9. Before you can add new logic to the existing Blueprint Event Graph, go ahead and drag the Shorter Instruction Set and Instruction Set variables into the Blueprint.

    Click for full image.

Scripting the Logic

  1. To get started with building your new logic, drag off the Shorter Instruction Set node and add the Intersection node from the Set Utilities interface.

    Click for full image.

  2. Now, connect the Instruction Set node to the Intersection node.

    Click for full image.

  3. Right-click in the Blueprint Graph to open the Context Menu, where you'll search for and add Event ActorBeginOverlap.

    Click for full image.

  4. Drag off the Other Actor pin of the Event ActorBeginOverlap node, search for, and add the Cast To FirstPersonProjectile node.

    Click for full image.

  5. Now, connect the Cast To FirstPersonProjectile node to the Intersection node.

    Click for full image.

    Basically, this means that if the First Person Projectile successfully collides with this Actor's collision box, call the Intersection node.

  6. After the Intersection node performs its operation on the Shorter Instruction Set and the Instruction Set, you'll want to store the results in the Resultant Instruction Set container. To do this, go ahead and drag off the Intersection node and add the Set Resultant Instruction Set

    Click for full image.

  7. Drag off the Set Resultant Instruction Set node and add the To Array node from the Set Utilities interface.

    Click for full image.

  8. To iterate through the Array's elements, go ahead and drag off the To Array node and add the ForEachLoop node.

    Click for full image.

  9. Connect the To Array Node with the ForEachLoop node.

    Click for full image.

  10. Now, you're ready to print the intersection's results to the Viewport. To do this, drag off the Array Element pin of the ForEachLoop node, search for, and add the Print String node.

    Click for full image.

  11. Connect the ForEachLoop node to the Print String node.

    Click for full image.

  12. At this point, you're ready to determine what the Resultant Instruction Set will contain. Let's say, for this example, that you want the Resultant Instruction Set variable to only contain Click, Left, Mouse, and Button. The first thing you'll want to do, is to perform the intersection on paper:

    Instruction Set

    Shorter Instruction Set

    Resultant Instruction Set (A ∩ B)

    Click

    Click

    Click

    the

    Left

    Left

    Left

    Mouse

    Mouse

    Mouse

    Button

    Button

    Button

    and

    Fire

    As you can see from the paper-study you just performed, items common to both Instruction Set and Shorter Instruction Set are stored in the Resultant Set container. Whenever you're performing logical operations on Sets, it's good practice to perform the operation on paper (or a whiteboard) before scripting the logic into your Blueprint Graphs.

  13. Now that you know what items you want to store in the Shorter Instruction Set container, go ahead and select Shorter Instruction Set to inspect the container's contents.

    Click for full image.

    As you can see from the highlighted image, Shorter Instruction Set is currently empty. At this time, if you were to perform an intersection of Shorter Instruction Set with Instruction Set, the Resultant Instruction Set container would be empty.

  14. Go ahead and fill the Shorter Instruction Set container with the following elements:

    Step3_22.png

  15. After inspecting your completed script, go ahead and click the Compile button.

    Click for full image.

  16. Finally, click the Save button before going back to the Editor's Viewport interface.

    Click for full image.

  17. From the Editor's Viewport interface, click the Play button to see the updated script at work.

    Click for full image.

End Result

As you can see from the video, when a First Person Projectile collides with the Display Set collision box, the contents of Resultant Instruction Set are printed to the Viewport. Looking at the printed items, you'll notice that the items contained in Resultant Instruction Set are not in any predictable order, which is a property of Blueprint Sets. Check out the next step to learn how to perform a Union of two Blueprint Sets.

Tags