Function vs Macro What is better?

I recently had the thought of the difference between a macro and a function.
For me they are most likely the same. They both can have input and output, both should be used multiply times,…
So what is the difference? When am i better running a macro and when a function? What is your experience with that?

Btw i’m working on a single player project. Maybe they have more meaning in Multiplayer.

3 Likes

As far as i know, you can’t call macros from outside. If you have logic that should be callable from outside (others actors etc) you will want to
use Functions/Events (Events have no Return). I only use macros to make my graph smaller.
For example if i need to compare an Enum, i don’t want to have multiple “Equal” and “Branch” nodes in my graph, i just make a macro out of them.

3 Likes

Like eXi mentioned, you can’t call macros from outside of it’s respective blueprint. One of the advantages of macros is that they can have latent functions (delays, etc…), while a function cannot. A macro can also take advantage of wildcard variables, and multiple execution pins, while a function cannot. Each has it’s own use, and you will likely find yourself using both of them. Personally I like using macros for all of my math/calculation nodes, or for doing special things like dynamically executing an event.

3 Likes

There is a bit of a difference in how they are compiled though.https://answers.unrealengine.com/que...acros-and.html

Also, you can use macros in different blueprints. Branches, while loops, sequence, are all macros. You’ll have the benefit of dealing with multiple outputs, but you lose out on some of the benefits of functions such as (I believe) the ability to call functions from within it. https://docs.unrealengine.com/latest...ary/index.html
https://www.unrealengine.com/blog/ma…-in-blueprints
https://forums.unrealengine.com/show...ables-in-Macro

Also, if you have some math that you have to keep doing over throughout your graph, you’ll probably benefit slightly more by using a pure function. You just can’t put anything that would cause a change in anything. So no calling anything that needs an execution pin in it, just things like < > == × \ + - or anything else without an exec pin.

2 Likes