Hi, I am trying to add an element to an array within Blueprints. I feed the “Add” node with my initial array (2 elements) and a constant number. I expected the array to be of length 3 when printed, but it still has two items. The “add” node doesn’t return a new array reference, so I used the existing array. Can anyone help out? Thanks!
Hello, you use correct node to add element to an array, but the way you use it is a little bit incorrect.
Let’s read your script by execute nodes:
Tick →
Add ( you are adding an element to a temporal array created by MakeArray node). But this array is not saved anywhere, this 3 element array is instantly cleared after execution of Add.
→
Print Text - check image below, it prints another 2 elements array created by MakeArray node:
To solve the issue you need to store your array in a variable. This should do the job:
Thank you Sitiana! Is there any page in the documentation that I am missing where this is explained in more detail?
No problem the thing is not about Arrays or Add node itself, it’s more because of how pure functions work.
Check Pure vs Impure section here: Functions in Unreal Engine | Unreal Engine 5.4 Documentation | Epic Developer Community
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.