No announcement yet.

Function vs Macro What is better?

  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    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.
    Open for contracted work | C++/BP (incl. Multiplayer) | Tutoring | VR

    My UE4 Blog/Page with Tutorials and more: Hit me for ALL the things!
    (Including 100+ Pages Multiplayer Network Compendium to get you started.)


      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.
      Last edited by Jamendxman3; 08-26-2015, 03:14 PM.
      Marketplace Assets

      Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
      Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
      Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread


        There is a bit of a difference in how they are compiled though.

        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.

        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.