Blueprint "Array Get by Reference", and edit struct elements directly

What’s the questions here? Could you post the setup that’s giving you the headache? Admittedly, structs are a tad fiddly.

If Get returns a reference, Set also treats params as refeence is better… I think. (Get is for getting a element from arrays, but we need some Set function to store the ref Get returns.)


Improve Get Array Item to return by-ref instead of by-value

>And it lacks what will happen if index is not valid.
This part is my mis-understanding of Resize node etc behavior, sorry.
My headache was
1.Resize an array of struct which contain arrays as member < I thought this does not add elements.(as step 3 seems not work.)
2.Get an element from the array < Can get. Can set values to arrays inside the struct after resize them.
3.Try to use the struct in another place (Get from array of struct). < Seems not exist. This is a mislead point.

Part of my troubles maybe depends on UE-6451.

Set Members in Struct node doesn’t work if the Struct is contained within an Array
(will be fixed in 4.16)

Not sure if I follow, can you show us an example of where you have trouble setting something?

This already works fine if you use SetMembersInStruct node.

Perhaps you’d want to start a new thread with a pertinent example.

>Set also treats params as refeence is better

Maybe having a new thread is better but
the problem is that we tend to think Set also treats arrays as refs if the input is a ref.
(Set converts a ref to a copy, though.)

In 1st image of Zhi Kang Shao’s post, “Temp Attackable Target” is a copy of “Enemies Within Attack Range”,
so any changes to Temp Attackable Target does not affect Enemies Within Attack Range,
and needs to write it back with Set Array Elem.

What we want is that changes to Temp Attackable Target also changes original array (Enemies Within Attack Range).

Please forgive a noob barging in, but i have strange dilemma.
I am following older tutorial on Youtube and in the version shown there there is just one ‘Get’ function. I am using 4.16 where i have two options (gasp). Which one should i choose to match the functionality of the tutorial, or older UE versions - ‘Get’ (a copy) or (a ref)?

The distinction likely doesn’t matter if you don’t know which to use.

Basically, if you want to make changes to the variable, you’ll need a reference. A reference points to the address of the original variable, which means that any changes to it are done to the original variable.
If you just want the variable in order to look at its content or store some temporary calculations inside of it, a copy is perfectly viable. A copy stores a copy of the value of a variable, as the name would imply. Make changes to it and the changes will only affect the copy, not the original variable.
Read up on pointers if you want to know more about the differences.
If you are using an old tutorial, it most likely works under the assumption that references are not possible. Meaning that the code will be intended for copied values anyway.

If the tutorial is that old, go with the copy.

This says fixed, but I couldn’t figure out how to use it. Does anyone have an example?

Ensure you Get by Ref (diamond icon):


Set Members, select that node and expose what’s needed in the panel:


Thank you!

I didn’t realize the thing about the details panel.