Download

Trying to Understand Macro vs Function

Hey Guys

I am trying to understand why the blueprint code below works only if I place it in a Macro and not in Function.

Basically I am spawning an item which contains a struct (Item Details), I am then modifying some details in that struct.

When I do this via a Macro, it works and the struct is update correctly, however if I try the same inside a Function, it doesn’t work, the struct is not updated. I don’t understand why. Screenshots Below: I don’t mind using Macros, but don’t understand why the macro works but the function doesn’t.

Thanks

Is the function Ticked as Pure, or is there a variable getting passed in as By-Val instead of By-Ref maybe? Overall, Functions don’t let you use Delays / Macros etc. Macros are a bit of a PITA imo. You can’t copy them properly or access them outside the Blueprint either. Plus often or sometimes they get used to hide bad / ugly code.

https://docs.unrealengine.com/en-US/…ons/index.html
https://forums.unrealengine.com/deve…what-is-better

No, the function is not pure. The only thing getting passed in is the ‘Item Details’ struct from the Spawned Item in the first screenshot. I’d rather not use the Macro, but since its not used anywhere else and is not complex, it’s fine in this case.

Is there a difference in the way code gets executed in a Macro as opposed to a function? Either way, it’s all good, was just curious. It is inside another function and so perhaps that is the issue.

Check all those references and variables inside function that are passed by variables not parameters, if all have correct values. Or do version of this function that passes them all by function parameters and see if it works.

Thanks guys, it turns out it was an issue with the variables and how I was using them within the function. Once i passed them in as parameters it all worked fine.