I believe that currently when retrieving an item from an array using the Array Get node, it is always a copy of the data inside the array. In some cases, such as when working with structs that contain arrays, it would be better if there was an option to get a reference to the struct inside the array so you can directly alter it. Specifically when the struct contains an array, it would be great if we could directly alter that array without having to make a copy of the struct and reinserting that into the outer array. Here is how it currently would be done:
I actually stumbled upon this âissueâ too! Had to work around my initial project âstructureâ that used arrays of structs!
Could be great though since structs always were a great way to organize stuff! (at least for me!)
There are a few places that struct referencing works fine! But specifically in arrays (and maybe a few other places) you just get copies of the struct which makes it both inefficient and hard to work with!
Hopes it gets fixed! Thank you!
That would be a great feature. I have a struct to fake 2 dimensional arrays and the blueprint code to manipulate the âinnerâ array is quite ugly and can be hard to debug. I would appreciate a simple solution.
Bump. I need it too. Everyone needs it. hahaha
It makes a really cumbersome Blueprint when we need to edit struct arrays.
I tried changing my struct to a class, but instead of extending Actor (I donât need all the Ticking etc), I did it with Object, to keep it lightweight. It just didnât cut it because we canât instantiate new Objects inside Blueprints. Thatâs a bummer. So, for now, Iâm making the cumbersome code of editing structs inside arrays.
Thanks for making the array request. I have logged this as UE-18616 to be taken into further consideration by our developers. Let us know if you have any further questions, have a great day!
Actually there is. Iâve mentioned an issue ticket in your thread and status was changed to âNot reproducible in 4.13â. So now the only thing we can do is to wait for 4.13 to test it
Well I just reproduced this issue in 4.13 so I hope it is still active
The various reports mentions above should help hopefully
Great job on starting this thread [MENTION=346351]Zhi Khang Shao[/MENTION]!
**C++ Solution**
An easy way to work around this if you have C++ powers and dont want to re-write a lot of code structure, is simply something like this:
I tried to think of a Victory Plugin generic solution for BP-only users, but I know well the complexity of arrays in Blueprints, under the hood. It may require engine modification :)
```
UFUNCTION(BlueprintCallable,Category="Your Class")
void SetBeatParam(int32 Index, FString Param, float Value);
void AYourClass::SetBeatParam(int32 Index, FString Param, float Value)
{
if(!Metronome_Beats.IsValidIndex(Index))
{
VSCREENMSGF("Array access out of bounds!", Index);
return;
}
if(Param == "Enabled")
{
Metronome_Beats[Index].Enabled = (Value > 0) ? true : false;
return;
}
if(Param == "Channel")
{
Metronome_Beats[Index].Channel = Value;
return;
}
if(Param == "Pitch")
{
Metronome_Beats[Index].Pitch = Value;
return;
}
if(Param == "Velocity")
{
Metronome_Beats[Index].Velocity = Value;
return;
}
VSCREENMSG2("Unknown param!", Param);
}
```
It's subject to spelling errors but if you do some output like I do at the bottom you can catch spelling errors easy :)
:)
I found that Break struct seems to return a ref but Set node seems to return a copy, (in 4.15.1)
So, if we use a local variable as a cache (Temp attackable targets in sample), itâs a copy.
By the way, tooltip of Get node seems wrong (if it returns a ref).
It says âa copyâ.
And it lacks what will happen if index is not valid.
(No error/log occurs but the values set to the struct member arrays seems to be ignored. This also be a possible bug.)
> No error/log occurs but the values set to the struct member arrays seems to be ignored.
Correction.
No error/log occurs when values are set to the struct member / member arrays (as if a struct exists),
but original array of structs which is connected to Get node input pin will not changed (as the struct Get node returned is not contained in the original array of structs).