Download

Blueprint "Array Get by Reference", and edit struct elements directly

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:

And this is what it could look like if there was an Array Get By Reference option:

It would be even greater if specific struct members could be altered without having to respecify all others.

I actually stumbled upon this ‘issue’ too! Had to work around my initial project ‘structure’ that used arrays of structs! :frowning:
Could be great though since structs always were a great way to organize stuff! (at least for me!)

I assumed it worked the way you are requesting, I hope they make this possible, would make handling item stacking much, much easier.

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! :smiley:

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.

Hey Everyone,

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!

  • Samantha

+1 for this =) Its cumbersome to do in Blueprints

Yes please, we need return updated array from “add” and “add unique” nodes.

Yes please!

Are there any updates on this feature?

This is crazy. How do you expect people to use this stuff? What’s the status?

Why you didn’t developed this node in the first release? This is a very simple and common function in every programming languages.

@SamanthaSutton can you please make UE-18616 public?

Still there’s no sign that someone is working on this.

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

@CleanCut UE-18616 was not added to the Public Jira site because it was a duplicate of other similar issues: UE-20424, UE-6451 and UE-24080

Thanks!

Well I just reproduced this issue in 4.13 so I hope it is still active

The various reports Samantha mentions above should help hopefully :slight_smile:

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 :)

:)

Rama

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).

Thanks.