What is the name of the node for getting an array element by index in Blueprints?
The primary node for getting an array element by index in Unreal Engine Blueprints is called Get (or Get (a copy)). This node is located in the Utilities → Array category and allows you to extract an element from an array at a specified index, returning a copy of the value. For working with arrays by reference, there is also a Get by Reference node.
Table of Contents
- The Get Node
- How to Use the Get Node
- Difference Between Get and Get by Reference
- Limitations and Features
- Alternative Methods for Accessing Elements
The Get Node
The Get node is the primary tool for accessing array elements by index in Blueprints. This node is located in the Utilities → Array category in the node browser. The node has two main inputs:
- Array - input for connecting an array variable
- Index - input for specifying the index of the element to extract
Important: The value in the field on the Get node represents the index of the array element to access (extract) from the Create Array node.
How to Use the Get Node
To use the Get node, follow these steps:
- Create an array type variable in your Blueprint
- Populate the array with values using the Add or Insert nodes
- Drag the Get node from the Utilities → Array category
- Connect the array variable to the Array input
- Specify the desired index in the Index field (starting from 0)
- Connect the node’s output to the desired action or variable
// Example of using the Get node
ArrayVariable → Get(Index: 2) → SomeVariable
Example: If the array contains elements [Element1, Element2, Element3, Element4], then:
- Index 0 will return Element1
- Index 1 will return Element2
- Index 2 will return Element3
Difference Between Get and Get by Reference
There are two primary methods for getting elements from an array:
Get (Get by Copy)
- Returns a copy of the array element
- Changes to the copied value do not affect the original element
- Safer to use as it prevents accidental data modification
- Is the primary and most commonly used method
Get by Reference
- Returns a reference to the array element
- Changes to the returned value directly affect the original element
- Useful for modifying elements without needing to use the Set Array Element node
- Requires careful use to prevent unintended data changes
Limitations and Features
Index Validation
- Valid array indices are in the range from 0 to N-1, where N is the number of elements in the array
- Attempting to access an index outside this range will cause a runtime error
- Always check the array length using the Length node before accessing elements
Performance
- The Get node operates in O(1) - constant time
- Very efficient even for large arrays
- Does not cause memory reallocation unlike add or remove operations
Context Limitations
- The Set Array Element node only works when setting values on the actor that owns the variable
- If the array is in GameState, you cannot set array elements from Character without special mechanisms
Alternative Methods for Accessing Elements
Find Node
- Finds the index of an element in the array by its value
- Returns -1 if the element is not found
- Useful when you need to get the index of an element rather than its value
Last Index Node
- Returns the index of the last element in the array
- Equivalent to using
Length - 1
Using Loops
- For Each - iterates through all elements in the array
- For Loop - iterates with access to indices
- More flexible but less efficient for direct element access by index
Comparison Table of Access Methods
| Method | Purpose | Return | Complexity | Use Case |
|---|---|---|---|---|
| Get | Get element by index | Copy of value | O(1) | Direct element access |
| Get by Reference | Get reference to element | Reference to value | O(1) | Modifying elements |
| Find | Find element index | Index or -1 | O(n) | Search by value |
| For Each | Iterate through elements | Current element | O(n) | Processing all elements |
Conclusion
Key Takeaways
- The Get node is the primary tool for accessing array elements by index in Blueprints
- It returns a copy of the element, ensuring data safety
- The node is located in the Utilities → Array category
- Indices start at 0 and must be in the range from 0 to Length-1
Usage Recommendations
- Always check the array length before accessing elements
- Use the Get node for reading values and Set Array Element for modifying them
- For complex element modification operations, consider using Get by Reference
Related Questions
- How to check if an element exists at an index? Use the Length node to check bounds before using Get
- How to modify an element at an index? Use the Set Array Element node instead of modifying the returned value from Get
- How to find an element’s index by its value? Use the Find node, which returns the index of the first found element