Why would I use BP function lib rather than BP macro lib?

Hi guys,

I’ve used BPF for days, sometimes a function in BPF need to call another function from the same BPF. At frist it’s fine. Maybe multiple stream levels been used, or these relationship of references get more complicate, I’m not sure since when a pin named “World Context” come out on some functions, and cause the compiling failed because the pin needs input.

After that I tried to use BP macro library instead(I always use Actor as its parent class, don’t know why). Macro doesn’t has context issue because no need to be compiled in BPM.

So I have this question. please feel free to post your opinion:)

It’s the same as in C++, the difference is on how they are compiled in to virtual machine bytecode. Macro is snippet of nodes which will be pasted to existing nodes when use it in blueprint and will be compiled together (thats why macro it self don’t have compile) and bytecode of that blueprint will contain code that is inside macro. Function on other hand are compiled sepretly and blueprint that use it only reference it in compiled code, during execution virtual machine jumps to that function to execute the code and go back… as any other function node (in case C++ based node virtual machine will call that function).

In blueprints the biggest difference of macro from function is that you can place any pi you like and create weird custom nodes, there function just is executed. If you will make functions out of macro there won’t be any practical differences, the only disadvantage is that code of a macro will be repeated over and over in compiled bytecode again on each use, increasing blueprint file size.

In C++ purpace of macros is very clear, aside of stamping repetitive portion of code in to existing code like blueprint macros do, they let you conditionally control what is compiled and what is not, control different variants of code based on build configuration (which includes for example what platform it is compiled to), something that blueprint macros won’t do as blueprint don’t have any precompilation features to support it.

Hi ,

Thanks for your quick reply.

I can see the differences between macro and function in C++. The BP function is pretty similar, except the input pin World Context. I don’t know how to deal with it when this World Context come out.

This sounds like a bug, it demends UWorld* as functions outside actor won’t have direct access to it and some functions that you use inside it require it (some function bindings hot UWorld* argument hidden). Did you tied to not place anything in it? is it giving you error if you do that?

yes, the compiling failed because of the error.

Maybe I have used Get Game State in a function which is referenced by some other functions inside BPF, in the meanwhile, I have multiple stream levels which makes engine confused( each level has its own GameMode settings, right?).

If my guess isn’t in the right direction, could you explain a little about this, please?

Main difference for me is, when you change macro it doesn’t change all instances of it, but function does.