How to get a reference from an array? (not a copy)

This seems a very basic and stupid question, I just loaded an array with instances, and now I need to perform very simple operations, like get the first one, or get a specific index from the array.

The only array functions I can see here are quite… fun (lack of a better word).

The GET returns a copy, I need the actual reference, not the copy.
The random instead returns the reference, but I don’t get the exact value I want.

Is there a way to do a “Get” and it returns the reference? Looks like a very basic feature that most of the cases should use IMHO.

image

Hi leofucci,

For things like Instances, the array will contain pointers to those instances rather than the whole class itself.

Passing a Reference to a Pointer is a bit redundant - that’s why for things like that you don’t see the “Get (ref)” node like you do for actual values.

2 Likes

Ok, how do I get a Pointer on index 9 instead of a copy of the instance? if that question suits you better.

use “Get a ref” for this

image

1 Like

index 9 will be a pointer, not a copy of the instance - the array “Get” will return a copy of the arrays pointer, but that pointer still points to the original instance , in the test below note that both the second read from the array and the actual object return the updated value:

image
(0 is the first value, logging goes upwards)

I thought this would be the solution, but as soon you select that option, it gives you this warning, and automatically changes to the Get(a copy)

I’m using latest version available at the moment, if you have latest installed, you should see the same.

:face_with_raised_eyebrow:

image

Oh man, the post there says

“For objects you always get a reference, the tooltip of Get here is misleading. Despite the returned object being a “copy” only, changes made to this item will be propagated back to the array.”

I need to check but is a big deal such a misleading message, to have a copy in server/client games would make a huge difference, need to try it out but it seems to be the answer.

2 Likes