This would work as you expect:
I am trying to pass a structure into a function and when I pass in a value it returns the wrong value
for example: a Make a structure with the Value of “Wood” print it to the console to check value, pass it to the function and print the value that function has received and the function would print the value of “Money” which is not the expected results.
This is the function I am calling
and this is where I am calling it wrong
Inside the Structure only contains a “String” value
It’s not a bug and what you’re seeing has nothing to do with structs. It’s the way you use the Random node. When you access a randomised value twice you get 2 different results, like in this example:
The above is very unlikely to print the same value since I’m asking for a random twice. When you press F, you send one random value to the Print and another random to the Function.
It’s a must have habit to save the result of random generation first (a dedicated int variable in this case) and use that to fetch stuff from the array. Either that, or store the fetched element.
in my example, visually I am not requesting another random value, what I am doing is passing in the random value I just found and checking what the value is inside the function …
are you saying that when I get “Some Val” from inside the function it goes all the way back up the line to what had called the function in the first place?
Thank you for clearing that, and yes I did indeed randomly get matching results sometimes which confused me even more, that is a weird way for it to work as it’s not the case when writing code
in my example, visually I am not
requesting another random value
Yes, you are, here:
are you saying that when I get “Some
Val” from inside the function it goes
all the way back up the line to what
had called the function in the first
place?
Precisely. That bunch of nodes will be evaluated again for every white execution wire. It’s a very old trap. The behaviour makes sense although I do admit it’s not intuitive at all.
In your example, if you mash F long enough, you’ll eventually get matching results since you only have 4 elements in the array.
Just to update this, while it was known how pure nodes are evaluated, now we finally know why:
A recent, informative post from one of the UE4 devs.