Arrays do not pass by reference into custom events

Hello,

The “pass by reference” check box is not working for arrays into custom events.

Steps to replicate

  1. Create a new blank level

  2. In the level blueprint create a variable named, “arrayNames”, which will be an array of the datatype “name”.

  3. create three entries for “arrayNames”, “A”, “B”, “C”.

  4. In the level blueprint, connect the beginPlay node to a foreach node and print out the contents of “arrayNames”.

  5. Create a custom event called, “test”.

  6. add a array of type “name” as a parameter to the “test” custom event. Name the parameter, “nameParam”.

  7. add a “clear” node to the custom event so it clears the array when the event is called

  8. Also, make sure to make “nameParam” pass by reference.

  9. connect the end of the for loop to call the “test” event custom event (after the loop reaches completed).

  10. connect the end of the “test” custom event to print out the contents of the array.

What you will get with this setup is the output of the following:
LogBlueprintUserMessages: [Untitled_C_3] A
LogBlueprintUserMessages: [Untitled_C_3] B
LogBlueprintUserMessages: [Untitled_C_3] C
LogBlueprintUserMessages: [Untitled_C_3] A
LogBlueprintUserMessages: [Untitled_C_3] B
LogBlueprintUserMessages: [Untitled_C_3] C

When what should be happening is:
LogBlueprintUserMessages: [Untitled_C_3] A
LogBlueprintUserMessages: [Untitled_C_3] B
LogBlueprintUserMessages: [Untitled_C_3] C

If we have a check box for pass by reference, then what happens in the custom event should be reflected in the variables after the event returns to normal execution. To me this seems like a major bug that should be fixed soon. Its basically causing me to program without functions (custom events).

HELP!!!

Hey , as far as I know, when you call that event, it doesn’t wait before it continues through your flow, it basically just fires off that call and keeps on going.

So the second ForEach loop and Print String is still outputting the array values contained in the array before it is able to clear them. If you move that second For each loop and just place it onto your Test Event, it will fire after the clear function and you should get the result you are looking for.

Hey ,

I think I know what your talking about and I recall having similar issues with the arrays updating properly. I chalked it up to be that sometimes in the runtime an array it would retain things that were effectively cleared by another process, but because of the flow split it would somehow pull the data out from a previously instanced variable. Confusing I know…

I believe I worked around it by just saving any Array data into a SaveGame file and then loading it from there whenever I needed it. Have you tried that, it would eliminate any references to old data as you are always loading the most current array info from the save file? Also will give you the ability to use that data across multiple blueprints.

Hi Akting,

The problem is that when I place print statements inside of the custom event, everything prints in order. Yet, when I return from execution, nothing has changed about my array. I have more complicated setups where I’m actually populating the array, but that would take a long time to explain each step. I am very certain that pass by reference does not actually work with arrays.

Can you create me test scene where pass by reference and arrays are working? Because, I’ve searched online and many other people have come to the same conclusion. It’s broken.

thanks,