What's the difference between Blueprint Macros and Blueprint Functions?

It’s in the nature of a function that you expect it to do something and return synchronously (immediately) like you would in any native code function/method. You can either use macros if you really need latent nodes or use Set Timer by Function Name inside a function.

I found (not sure if mentioned in the checked answer) one big difference.

If inside a macro/function (imagine they are equal in terms of content) there’s some kind if branching (true/false or other stuff), and, for example, true leads further, and false leads nowhere (dead end):

  • in case of function, everything you put after it, will be executed even if the function inside itself hits dead end.
  • macro, however, will stop execution of the following code if it’s not fully executed.
1 Like

It sounds like there are almost no situations where you should prefer a function over a macro… is that correct?

No, a function would likely be preferable, since it only has to compile once and then can be used over and over again, whereas for each time a macro is used, it must compile ALL the nodes it contains over again. But… macros can contain latent nodes (such as timelines and delays) and functions cannot.

My set of blueprints always compile in less than a second, no matter how many macros I use, which means that whether “it must compile nodes over and over again” makes absolutely no difference to me. However, I haven’t worked on an extremely large project in Unreal yet. Is blueprint compilation time an issue?

Ok, I have found another feature unique to functions: they can facilitate inter-blueprint communication, while Macros (as far as I can tell) cannot.

Macros can’t be inherited or overridden either like functions can. If you want to share a macro it has to be placed in a macro library. You can’t use a latent macro in a function, but you can use a function anywhere. There are many reasons as to why functions should be preferred over macros the main reason being easy and effective reuse.

Thank you. This is a solid, clear example of when have to use a macro instead of a function. That and using latent nodes. All the other examples seems to more about personal preference.