Is there a way to use Blueprint Function Libraries or an equivelent feature for non-actor blueprints?

The following may not be entirely accurate anymore since its been a while I look into this. From what I remember function libraries need a “World Context” object (hidden function input), essentially any UObject that implements GetWorld. Actors, ActorComponents and a few other classes implement GetWorld accordingly so these can use the function library functions. All classes that directly inherit from UObject have the default implementation of GetWorld (following the outer-chain). However this default implementation is not considered “valid” because the class does not explicitly override GetWorld resulting in functions requiring a “World Context” object not being callable.

There are two solutions I’m aware of (unfortunately both involve some native code):

  • either create a C++ class derived from UObject where you implement GetWorld in a valid way. You can find a couple of examples for this if you look at existing GetWorld implementations from the engine itself. This will make the function library functions callable again in classes inheriting this new class. For some reason the “World Context” object pin will be visible and must be connected manually though (unlike Actors, Components, etc.). Using a Self node is sufficient for that though.
  • create an empty C++ class derived from UObject and add meta=(ShowWorldContextPin) in the UCLASS(...) macro. The function library functions should be callable again for classes derived from this new class. And as the name of the metadata suggests the “World Context” object pin will also be visible here and must be connected manually. Since the object itself may or may not have a valid way to GetWorld (depending on the outer) you need to decide whether you can pass Self or another object as the “World Context”
1 Like