Struct with array problem

I have an array of a struct I created and I can’t seem to change the values of an array inside the struct.

Basically I have a box (which is an array of baskets).
Inside the box I have some baskets.
each basket can hold different kinds of fruit(array of fruit).

Adding a basket to the box works just like any other array, but adding a fruit to any of the baskets refuses to work.In my first attempt I tried using the array Get node to reference the first basket and then break the struct and do another get on the fruit array but it doesn’t work.

any ideas on how I can add additional fruit to my baskets that are inside the box?


Only an idea on the fly as i haven’t do structs but if no one has a better way, as you can add baskets, maybe can you use a temporary basket. Get the basket you want update. Set the temporary with it. Add your new fruit in temporary. set / replace / (delete and add) the basket with the temporary ? (not sure for the last one of the best solution)

I came across this problem and solved it using Fen’s suggested method. When you get a struct from the array, its actually a copy. The array inside that struct is thus not the one stored in the outer array.

What you need to do is store the array that you retrieved in a temp array variable, add your new element to that, make a new struct copying all previous data plus the new array and replace your previous struct in the array. Does that sound like a lot of work? Sadly it is. :frowning:

This is really what I was hoping the answer wasn’t. I would have thought it would be as simple as two array Gets to accomplish a simple task.

A way around this would be by containing your struct in a UObject. When you have an array of object references, when you get an element from the array its a copy of a reference, but that copy still points to the same object.

Thanks for the heads up. I think I figured this out though. Setting up a temp array isn’t so hard, just looks ugly no matter how I do it.

Yes it does look ugly. I’m hoping that there will be a Array Get By Reference some day. In fact… goes to feedback for Epic forums

Edit: Blueprint "Array Get by Reference", and edit struct elements directly - Feedback for Unreal Engine team - Unreal Engine Forums

Hopefully they will consider it.

Thanks for posting that, I totally agree it would be great to be able to do it the simpler way. Your example was nice to look at as well.