array get (a copy) is reference actually ??

I’m back to UE after some break. Previously I remember you could use “get (a copy)” or “get (a ref)” nodes when working with arrays to get a copy or reference to an object.

Right now I’m confused. When working with array of ints I can get a ref or a copy and they work as intended.

However, when I have an array of objects I can only use “get (a copy)”. When I try to use “get (a ref)” it gets automatically converted to “get (a copy)”. Moreover, it works like gettting a reference, NOT a copy.

Here’s an example BP of a barrel:

In it I add self to an array, change an int and print the value from the object in the array. Since I’m working with a copy (supposedly), the value of object in the array should not change. But it does and in fact prints 25, instead of 0.

The get is “get (a copy)” node:

My questions are:

  1. why can’t I use “get (a ref)” node?
  2. why does “get (a copy)” node modify the original object, as if it was a reference?

Right click the get node and you can switch it to get by ref at the bottom

Thanks. For me this option is disabled though:

I think you are already returning by ref. The option becomes greyed out once you enable return by ref.

Objects will always be passed around by reference in blueprints

As far as I know there is no way to duplicate an object in blueprints only, you’d have to do that through C++

But it’s not super common to want to duplicate objects, so maybe you should look over your approach once more and see if there is a more conventional way of doing what you want to do

@3dRaven Yeah I thought so, but the tooltip’s description of the node says it’s a copy (like in my first post).

@Zeaf Thanks. Yeah I don’t need a copy, +1 to what you wrote. But I’m just confused, if it’s a reference then why is the “get (a copy)” node shown by default when you try to place it. If it’s a ref it should be “get (a ref)”…

It’s one of the engine inconsistencies.

Looks like Unreal Engine now automatically converts “get (a ref)” to “get (a copy)” for object arrays, but it still behaves like a reference in practice. You might need to adjust your logic accordingly when working with arrays of objects.