Download

Create UObject, that acts as function container

Greetings,
i try to create a UObject, that only acts as a container for different functions. My idea was the following: Having a blueprint with a member of UFunctionObject. Create blueprint classes of UFunctionObject, BPFunctionObject, and overriding the function, lets call it func1, in them with different logic. Then setting those BPFunctionObjects to the first blueprint. The blueprint would call the func1 and depending on the BPFunctionObject the result would differ. My problem is now, that i cant find a way of creating an BlueprintImplementableEvent on a static function. I do not need any kind of state on the BPFunctionObjects, they should only operate on the inputdata in func1. The whole point of them is to hold different functions, so i can easiely switch them in my main Blueprint. On the long run id like to create a map of said BPFunctionObjects. The UObjects should not be spawned in the level, id like to have them only in the contentbrowser.


UCLASS(Blueprintable) class MAPCLICKHANDLER_API UCLickEventLogic_Base : public UObject {
GENERATED_BODY()
public: UCLickEventLogic_Base();
~UCLickEventLogic_Base();
UFUNCTION(BlueprintImplementableEvent)
static void ClickAction(AActor* ClickedActor, AActor* ActiveActor);
}

I get

Any advice would be much appriciated.
Kind regards

Have you looked at BlueprintFunctionLibrary?



/**
*
*/
UCLASS()
class UAWBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()

public:

/** Checks if spec has any effects */
UFUNCTION(BlueprintPure, Category = Ability)
static bool DoesEffectContainerSpecHaveEffects(const FAWGameplayEffectContainerSpec& ContainerSpec);

/** Checks if spec has any targets */
UFUNCTION(BlueprintPure, Category = Ability)
static bool DoesEffectContainerSpecHaveTargets(const FAWGameplayEffectContainerSpec& ContainerSpec);




Yes i looked into them. They wont work for my use case, because blueprint libraries are globally callable an not bound to a class. I was able to create a clickEventLogicBase object with a custom factory, assigning it to a variable in my blueprint and running a blueprint Callable function on the object. But if i tried to create a blueprintClass and override a BliueprintImplementableEvent on it, the variable wont take this blueprint and the function can not be called. How can i make it happen, that i am able to override the function with blueprintcode and still be able to call it?

You can’t declare static events. Events must be member functions of an instantiated instance.

What is the actual use-case here?

The use-case is the following: I try to map a function to a Gameplaytag. I have a game with multiple character that can be controlled via mouse input. They will react differently on any given input though. For example: I do o right click on the terrain. I detect the click in my player controller and create a gameplaytag ClickRight.Terrain. Then the tag will be checked against the map and i wll find the function object. It will run the function and print “Hello” to the screen. Now i switch characters. The object in the map for the Tag RightClick.Terrain will be switched with it. When i now run the function assigned to the map i get a print “Hello2” because the function is overridden in blueprint differently. I already get the system to work with c++ functions (marked as bBlueprintCallable), but if i try to create a blueprint from my class an override the function as a BlueprintImplementableEvent, i cant assign the Blueprint to my map anymore. With this setup i can get rid of the static functions and use non static functions instead,