[BUG] What happened to Blueprint Function Library 4.3.0

Hello! What happened to functions and why it was removed variables?

Error variable “name” cannot be declared in FunctionLibrary “name”
**My project involved over 430 functions and about 6000 variables… ;(

My problem is slightly different. I just made a custom library, but no variables. In my blueprints if I use a function from my library everything works, until I close and reopen blueprint using function. At that point, blueprint won’t compile anymore until I delete library function and re-add it. No changes being made, blueprint(s) just refuse to compile or save until library function has been replaced (even with same library function).

Hello,

Thank you for your report. We were not able to investigate this on engine version you reported, but there have been many version changes to UE4 since this question was first posted. With a new version of Engine comes new fixes and it is possible that this issue has changed or may no longer occur. Due to timetable of when this issue was first posted, we are marking this post as resolved for tracking purposes.

If you are still experiencing issue you reported in current engine version, then please respond to this message with additional information and we will investigate as soon as possible. If you are experiencing a similar, but different issue at this time, please submit a new report for it.

Thank you.

Hello! Problems with variables was not available in version 4.2.
It would not be scary, but before variables were created possibility of version 4.2 In later versions of all libraries now not working… screenshot attached.

In later versions it was impossible to create variables…

Hi xangs,

Thank you for your feedback. I have used information and images you’ve provided to generate Report [UE-5251]. Should this issue be addressed in a future release an update will be posted to this thread. In meantime, try using this set up as a workaround:

Hello!
I have been, unfortunately, if you create a function, then use data variable it impossible to relate only to originally created functions.
Because it is impossible to use for some reason dynamic handling and writing of data to contents of actor. Used functions, but was very surprised that updates and they stopped working. :wink:

I have added this information and included additional pictures to bug report to better illustrate significance of this issue. As I mentioned before, should this be addressed an update will be added to this thread.

Thanks again for your input.

Thank you!

I got same problem? How to store shared variables in a function library?

still does…;( promised to fix it.

Hi Xangs,

While I had reported this as a bug it turns out this is a deliberate fix as developer explained, “Function libraries can’t track state, so only variables allowed are local variables. fact they used to be allowed was an oversight, and dangerous.”

That sounds - strange.

If shared variables, accessible to a bunch of functions in their own namespace would be “dangerous” I wonder how simple static classes were working all these years. :wink:

So what solution are we supposed to use then to pack together functionality in a module-like structure? Pack every feature in an Actor-derived Blueprint and instantiate it in world at 0,0,0?! (That’s in fact only solution which works for me right now and it’s simply horrible to maintain).

;)) Says is true. Very suspicious, simply remove ability to create a variable in function. This is why working in version 4.2.1.

Hi guys,

As mentioned, this functionality is intended, and it was implemented incorrectly when function libraries were first introduced. I can understand how it might be frustrating to be using function library a certain way and then find out that wasn’t correct way to be using it, and I’d like to help explain why and help you figure out how to achieve what you need in your project.

A Blueprint Function Library allows you to create functions that can be accessed anywhere. As such, these functions must be self-contained, otherwise same function in multiple places accessing public variable can cause all sorts of problems, least of which is overwriting of these variables in places you wouldn’t expect, and worst of which can cause project crashes. In this respect, a function from function library is much like a Macro, and Blueprint Function Library is just container for these functions. functions within library do not interact with each other, and are entirely independent of each other.

You can still use Local variables, however, and achieve much of same effect. If you create an input and an output for your function, local variables allow you to store information you need while inside function and output whatever you need.

If you have a use case that does not work with what I described above, let me know and we can try to figure out how to do it either inside function or using some other method in Blueprints. Remember that function library simply stores your collection of functions, each of which are self-contained and do not share variables explicitly, though you can pass variables in and out.

Hope that helps!

Hi , and thanks for your explanation.
I see your point, but that doesn’t really solve my problem. When sharded variables are forbidden now in function libraries, what structure should I use to cluster blueprint functions which HAVE TO access same variables and which are NOT independent? How to simulate something like a static class or a singleton?

Should I use an actor and spawn it in every scene at some random location with a getter-method called from outside which would give back already spawned instance if present?

Are they any code-only-blueprints in UE4 which I could use instead of function libaries to implement just ‘stuff’ which can be called from outside?

I currently use function libs to extend abilities of my character while using one file per skill (can’t pack anything in same file because that doesn’t play well with GIT and there are many other people involved which would now edit same blueprint over and over again).

If you absolutely need to share a variable between functions, that’s exactly what you’d use an Actor Blueprint for. Using a standard getter method and casting to this functions BP would way to do it, as you suggested.

Can you show me some images of an example of a situation where you would need a shared variable for these functions? I would like to make sure we’re not missing a workaround that would allow you to use a function library.