Unreal Engine Blueprints Functions, Events, and Macros Questions and Answers — Questions and Answers
Question 1: A developer needs to create a reusable piece of logic that includes a Delay node. This logic will only be used within a single Blueprint actor. Which of the following should be used?
- A Pure Function
- A Custom Event
- A Macro (Correct answer)
- An Impure Function
Correct answer: A Macro
Macros are the correct choice because they can contain latent nodes like Delays, and they are designed for reusing sequences of nodes within the same Blueprint. Functions, whether pure or impure, cannot contain latent nodes. A Custom Event could be used in conjunction with a Delay, but a Macro is the most direct and appropriate way to encapsulate a reusable graph segment with a Delay for use within one Blueprint.
Question 2: In a multiplayer game, you need to ensure a client can reliably tell the server to perform an action, such as casting a spell. Which of the following is the most appropriate tool for this client-to-server communication?
- A Macro
- A Blueprint Interface function
- A replicated Function
- A 'Run on Server' Custom Event (Correct answer)
Correct answer: A 'Run on Server' Custom Event
Custom Events can have their replication settings adjusted. A 'Run on Server' event is specifically designed for a client to execute code on the server, which is essential for authoritative game logic in multiplayer scenarios. Standard functions do not have built-in replication settings in Blueprints, and while an interface could be used, the core mechanism would still rely on a replicated event. Macros cannot be replicated.
Question 3: Which of the following statements accurately describes a key difference between Blueprint Functions and Macros?
- Functions can have multiple execution output pins, while Macros can only have one.
- Macros are compiled as shared, reusable code, while Functions are copied into the graph at each call site.
- Functions can have local variables, while Macros cannot. (Correct answer)
- Macros can be called from other Blueprints, but Functions are restricted to the Blueprint they are created in.
Correct answer: Functions can have local variables, while Macros cannot.
Functions have their own scope and can contain local variables that exist only for the duration of the function's execution. Macros, on the other hand, are expanded into the graph where they are placed, sharing the same scope and variable space as that graph, and thus do not have their own local variables. Macros can have multiple execution outputs, while functions have only one. Functions are compiled once and called, whereas Macros are essentially a copy-paste of nodes.
Question 4: A developer is creating a complex mathematical calculation that will be used in many different parts of their Blueprint graph. The calculation takes several inputs and produces a single float output. It does not need to alter any actor state or variables. What is the most optimal choice for this task?
- A Macro with no execution pins.
- A Custom Event.
- An Impure Function.
- A Pure Function. (Correct answer)
Correct answer: A Pure Function.
A Pure Function is the ideal choice for this scenario. Pure functions are designed for calculations that return data without causing any side effects (i.e., they don't change the state of the game). They don't require execution pins, making the graph cleaner as they can be wired directly to data pins. The engine automatically executes them when their output data is needed.
Question 5: You are working on a character Blueprint and want to organize a section of the Event Graph that checks if the player has a specific key, unlocks a door, and plays a sound. This sequence of actions will be triggered by multiple different events (e.g., 'OnInteract', 'OnOverlap'). What is the best way to implement this reusable logic?
- Create a Macro containing the logic and call it from each event.
- Copy and paste the entire sequence of nodes for each event.
- Create a Function and call it from each event. (Correct answer)
- Use a Sequence node to connect all triggering events to the logic.
Correct answer: Create a Function and call it from each event.
A Function is the best choice here. It encapsulates a specific piece of functionality (unlocking a door) that can be called from multiple places. This is more organized and maintainable than copying and pasting nodes. While a Macro could also work, Functions are generally preferred for self-contained behaviors that can be called from other Blueprints and can be overridden in child classes, making them more versatile. A Sequence node would not work as it executes its outputs in order from a single input, it doesn't consolidate multiple inputs.
Question 6: Which of the following can have multiple input AND multiple output execution pins, allowing for complex branching logic within a single node?
- A Custom Event
- A Pure Function
- A Macro (Correct answer)
- A Timeline
Correct answer: A Macro
Macros are unique in their ability to have multiple input and output execution pins. This allows developers to create custom flow-control nodes, such as a branch that checks a condition and fires one of several distinct output execution pins based on the result. Functions are limited to a single execution input and output, and Custom Events only have a single execution output.
A developer needs to create a reusable piece of logic that includes a Delay node.
This logic will only be used within a single Blueprint actor.
Which of the following should be used?