In function library, is it good practice/safe to use local variables to clear and temporarily store data each time when a function is called?

hi UE folks, I have a working AddItem function, currently I’m using local variables in the function library to reset and then temporarily store data each time when the function is called, I was wondering if this is a good idea (since I come from C# Unity) I’m not that familiar how I can temporarily store values without creating variables(using the plus button) in blueprints, also I decided to post this topic mainly because I’m not sure like when I call the method from timers (like Unity C# Coroutines), if two timers call the same method at the same time will it break things since its clearing the local variables on each call at the same time?, included a image below

P.S: I have also come across macros, that they can be used to temporarily store data though the process is a bit complex for doing that, but I plan to use it but as a beginner I wonder if my current approach is okay so I can just keep my code like this?

P.S: ignore the ‘temp_additem_filter_array’, I have removed and updated my code (due the var not being used)

There is no problem with creating and temporarily storing data in local variables. That’s what they’re for! More so, the Clear step that you’re taking is unnecessary. Function local variables are already set to their default value when entering into the function. This is true for any blueprint, including function libraries. They are, by definition, temporary so you wouldn’t need to name them temp_anything as well.

While we’re here, there are nodes available for getting the function inputs without having to drag connections all over the place. You can’t reassign them in the blueprint (that’s what a local variable might be good for), but they still make thing much nicer.

I think 5.5 added the handy little “→f” icon, but it might have been earlier than that.

1 Like

Function local variables are already set to their default value when entering into the function

so each time when I call different functions in the function library these variables they are local or only exists within the scope of the called function?, I thought they were global private static variables like in C#

there are nodes available for getting the function inputs without having to drag connections all over the place.

dang >_<, I didn’t know lol, now I don’t have to keep moving around alot in the blueprint design xD, thx 4 the tip, this is really useful :grinning_face:

That’s correct. You should notice that if you swap between functions in the library, the set of local variables that you have will change.

I’m pretty sure C# has function local variables too. I guess it depends on how you write your code.