Originally posted by Raildex_
View Post
Announcement
Collapse
No announcement yet.
Blueprint "Array Get by Reference", and edit struct elements directly
Collapse
X
-
SuperGrid: Marketplace Page | Feedback Thread | Demo | Website
Level design and prototyping for newbies
-
Twitter @UnrealSamantha
Mobile Development Troubleshooting Guide | Package and Deployment Troubleshooting | How do I report a bug?
Call me to a thread by posting this: [MENTION]Samantha Sutton[/MENTION]
Comment
-
Originally posted by zeOrb View PostActually 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
The various reports Samantha 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
Code: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
RamaLast edited by Rama; 09-28-2016, 08:46 PM.100+ UE4 C++ Tutorials on the UE4 Code Wiki, including UE4 Multi-Threading!
UE4 Marketplace: Melee Weapon Plugin & Compressed Binary Save System Plugin | Rama's C++ AI Jumping Videos | Vertex Snap Editor Plugin
Visit www.ue4code.com to see lots of videos about my C++ Creations! ♥ Rama
Comment
-
Originally posted by Rama View PostWell I just reproduced this issue in 4.13 so I hope it is still active
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.)
Comment
-
> 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.
Comment
-
Originally posted by Dev.TMG View Post> 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.
Comment
-
If Get returns a reference, Set also treats params as refeence is better.. I think. (Get is for getting a element from arrays, but we need some Set function to store the ref Get returns.)
UE-24080
https://issues.unrealengine.com/issue/UE-24080
Improve Get Array Item to return by-ref instead of by-value
>And it lacks what will happen if index is not valid.
This part is my mis-understanding of Resize node etc behavior, sorry.
My headache was
1.Resize an array of struct which contain arrays as member < I thought this does not add elements.(as step 3 seems not work.)
2.Get an element from the array < Can get. Can set values to arrays inside the struct after resize them.
3.Try to use the struct in another place (Get from array of struct). < Seems not exist. This is a mislead point.
Part of my troubles maybe depends on UE-6451.
https://issues.unrealengine.com/issue/UE-6451
Set Members in Struct node doesn't work if the Struct is contained within an Array
(will be fixed in 4.16)
Comment
-
Originally posted by Dev.TMG View PostIf Get returns a reference, Set also treats params as refeence is better.. I think. (Get is for getting a element from arrays, but we need some Set function to store the ref Get returns.)
Originally posted by Dev.TMG View PostPart of my troubles maybe depends on UE-6451.
https://issues.unrealengine.com/issue/UE-6451
Set Members in Struct node doesn't work if the Struct is contained within an Array
(will be fixed in 4.16)
Perhaps you'd want to start a new thread with a pertinent example.
Comment
-
>Set also treats params as refeence is better
Originally posted by Everynone View PostNot sure if I follow, can you show us an example of where you have trouble setting something?
the problem is that we tend to think Set also treats arrays as refs if the input is a ref.
(Set converts a ref to a copy, though.)
In 1st image of Zhi Kang Shao's post, "Temp Attackable Target" is a copy of "Enemies Within Attack Range",
so any changes to Temp Attackable Target does not affect Enemies Within Attack Range,
and needs to write it back with Set Array Elem.
What we want is that changes to Temp Attackable Target also changes original array (Enemies Within Attack Range).
Comment
-
Please forgive a noob barging in, but i have strange dilemma.
I am following older tutorial on Youtube and in the version shown there there is just one 'Get' function. I am using 4.16 where i have two options (gasp). Which one should i choose to match the functionality of the tutorial, or older UE versions - 'Get' (a copy) or (a ref)?
Thanks.
Comment
-
The distinction likely doesn't matter if you don't know which to use.
Basically, if you want to make changes to the variable, you'll need a reference. A reference points to the address of the original variable, which means that any changes to it are done to the original variable.
If you just want the variable in order to look at its content or store some temporary calculations inside of it, a copy is perfectly viable. A copy stores a copy of the value of a variable, as the name would imply. Make changes to it and the changes will only affect the copy, not the original variable.
Read up on pointers if you want to know more about the differences.
If you are using an old tutorial, it most likely works under the assumption that references are not possible. Meaning that the code will be intended for copied values anyway.
tl;dr
If the tutorial is that old, go with the copy.
Comment
Comment