x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

What does Pass-By-Reference do?

I've been working with UE4 for 1-2 months now so I'm pretty familiar with most of the Blueprint/Event Graph stuff, however I am still a bit confused about the Pass-By-Reference checkbox on function/event inputs.

I found plenty of threads here talking about Pass-by-Ref problems, but none that actually explain what it is, so I looked online and found a pretty straightforward explanation here:

http://stackoverflow.com/questions/373419/whats-the-difference-between-passing-by-reference-vs-passing-by-value

But I would really appreciate if someone could give me a quick example within the context of Blueprints to help me fully understand this and how it should be used properly.

Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Jan 08 '15 at 03:47 PM in Blueprint Scripting

avatar image

JeromeParent
1.2k 63 33 96

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

I found this question when I was looking for more information about this same subject. Since this was asked almost a year ago with no response I'll try and answer it myself with what little I know.

Giving a function an input that has pass-by-ref enabled allows you to modify what ever variable that you plugged into that function when calling it. Normally, without using pass-by-ref you would have to know exactly what specific variable you want to assign a value to and assign it to that specific variable in the function, or return the value at the end of the function and assign it outside and after the function was finished. Pass-by-ref allows you to tell the function that whatever variable I plugged into this function, that's the variable I want to change.

Lets say you have a function that doubles a character's attribute score. You have 6 different attributes but you only want to double one attribute at a time. Now you could set up the function to receive the attribute score you want to change as a normal variable, process it inside the function to double the value, return the new score and then assign the value back to the attribute outside the function. You could also make 6 different functions that double only a specific attribute each. The best method perhaps is making one function and using pass-by-ref to calculate and assign it back to the plugged in variable in one function. That way you could use one function to double any attribute you plugged into it.

Checking the pass-by-ref box on the input variable for a function turns the variable to a diamond shape instead of a circle for easy identification. From what I can tell though, to use it properly you can not assign it to a local variable because the local variable does not retain this ability. To assign it back to the input variable you have to drag off the input node reference variable (the diamond) for it to work. To assign anything to it drag off the diamond and call "Set (by ref)". I've only tried this with integers.

Sorry for the long winded post, that's why I usually leave it to others who are better at explaining these things.

more ▼

answered Dec 16 '15 at 04:48 PM

avatar image

BackedUp20
206 2 65 11

avatar image CR33PY Sep 28 '16 at 02:37 AM

Appreciate the follow through!

avatar image abroute Nov 09 '16 at 12:39 PM

thanks, I'm looking for the answer of a question "pass by reference". thanks again.

avatar image zaksi Jun 06 '17 at 10:51 AM

So is there any way once I pass the variable as reference, can I make a local variable that takes that reference and retains it's pointer ability? If not this way of working with references is very impractical (in terms that makes everything visually more cluttered).

avatar image mrpdean Jun 15 '17 at 11:23 AM

I would like to know this as well. Though after testing it just now it doesn't seem to work. Updating the local variable doesn't update the original reference. Hoping there is some clever workaround as it does make it difficult to keep large function graphs nice and tidy.

avatar image Lidia M. Dec 01 '17 at 05:01 PM

This is only for Blueprints.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

For visual learners and as a supplement to BackedUp20's answer:

Pass-By-Reference blueprint example

passbyreference.png (146.4 kB)
more ▼

answered Nov 18 '16 at 02:24 PM

avatar image

B3RyL
146 3 10 21

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question