So, it’s worth noting that Blueprint function libraries as created in C++ are not really classes you instanciate, as such; they’re generally a whole series of static functions.
So, for instance, normally with your AMyCharacter
class you defined in MyCharacter.cpp/MyCharacter.h
, you create instances of that class. There could be 2, 3, or 17 different AMyCharacter
instances in the world at a time.
If you make an UMyBlueprintFunctions
library, there is only one of it, and you call functions on it directly. Generally, this means you’ll need to pass in anything the library needs to work with. So yes, it would be like FMath::xx
, to use your example. If I wanted to have a function where I would launch one of your characters into orbit, it would be something like this (and I apologize if I mess something up in this hypothetical code; it’s 2am here and I’m going on pure memory):
UCLASS()
class UMyBlueprintFunctions : public UBlueprintFunctionLibrary
{
/**
* @brief Launches a character into space.
* Given a character and gravity, calculate the necessary escape velocity
* to escape the gravity well, and apply it to the character.
* @param Victim The character to be launched.
* @param ZGravity The downward gravity we want to escape.
* @param EnterLEO Should we take pity and allow the victim to attain
* Low Earth Orbit, or leave them traveling onwards eternally?
*/
UFUNCTION(BlueprintCallable, Category="My Very Useful Things")
static void Yeet(AMyCharacter *Victim, float ZGravity, bool EnterLEO = false);
// other functions
}
Then if you were in some other bit of code and had a character you wanted to launch into space…
#include "MyBlueprintFunctions.h"
void AMyAstronautCharacter::BecomeRocketman()
{
UMyBlueprintFunctions::Yeet(this, CurrentGravity, true);
}
Or whatever. (Again, it’s 2am. I accept no responsibility for the nature of my ridiculous example code.)
Meanwhile, the fact that you’ve got that UFUNCTION(BlueprintCallable)
there means that these functions will show up (globally) for Blueprints as well; there will be a Yeet node that takes a character, a float value, and a boolean, and in the list of Blueprint nodes it would show up in a category called My Very Useful Things.
You could thus have some other bit of code – even in a blueprint – which could Yeet()
a character.
Does that help a bit?