What is the significant difference between using “get (a ref)” and “get (a copy)” nodes?
Especially in the context of this example:
Is there a performance difference or something else?
What is the significant difference between using “get (a ref)” and “get (a copy)” nodes?
Especially in the context of this example:
Is there a performance difference or something else?
A copy is just that, a copy. But if you use get ref, any modifications you make will be written to the original.
In the first example, you don’t need to re-make the item and write it back. If you update any of the broken-out fields, that will be written back to the array element.
As ClockworkOcean said:
Getting a copy is actually creating a new chunk of data that contains the same data, but is otherwise unrelated to the array element.
Getting a ref (reference) is actually getting the array element itself.
If you modify the ref, the changes are reflected back into the array.
If you modify the copy, the changes are not reflected back into the array.
–
My advice is you use the “Get (a copy)” nod for when you just need to read the data from the array, but you don’t want to modify it. (Like retrieving the score of a player from an array of player scores)…
An you should use the “Get (a ref)” node for when you want to change the data from the array. (Like giving a player more points in an array of player scores).
Hope this helps
Thank you so much! Round pins in Break out node always confused me and i’ve never tried using Set By-Ref for variables inside before. But this is what I need!
Also check out the SetMembers node ( drag a pin off a structure to get it ).
That’s about right, and what we’d expect, from the name and tooltip, but I’ve read Get a Copy only makes a copy for reading primitives (float, int, bool, etc.), but not so for objects.
Blueprints stores objects in arrays by pointer - like, an array of BP_BigHeavyObject will actually have pointers to those objects - and Blueprints will only get you the dereferenced pointers, so any changes made will be to what was pointed at, that is, the original object.
So - if you use Get a Ref for an object in an array, Blueprints will change this to Get a Copy (with a misleading tooltip), but you are actually accessing the original object, not a copy.
If You use get a (copy) then the items will not be added in this example and if you used a ref a (copy) it will add items in that like given below is an array of structure of actors array test it like that and you will find the difference.
Are they they same speed to do operations on? I have a situation where I am reading from arrays, but not altering them, and writing to a new array (with new data, not same data).
If they are the same speed, I would then assume it is better to use “ref” to avoid duplicating memory usage?
i imagine Ref would be faster but not enough to even think about, just do what suits your code better