BlueprintImplementableEvent not fired on UObject

Heyo,

I seem to have some issues with firing events on custom UObject’s. It’s a simple setup that I cannot get to work no matter what I try.

Class definition
I’ve created a custom class inherting from UObject. The definition of the class looks something like this:

UCLASS(Blueprintable)
class MYGAME_API UMyCustomObject : public UObject
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintImplementableEvent)
    void OnCustomEvent(ACharacter* Caller);
}

It’s a simple class with only a single function, expecting the functionality to be added in a blueprint inheriting this class.

Function calling
On another class inheriting from AActor, I’m firing the event OnCustomEvent on a new instance of my UMyCustomObject, created by TSubclassOf.

void ASomeActor::SomeFunction(ACharacter* Caller, TSubclassOf<UMyCustomObject> CustomObject)
{
    if(CustomObject)
    {
        // Simple UObject creation.
        UMyCustomObject* MyObject = NewObject<UMyCustomObject>(CustomObject);

        // Fire the event.
        MyObject->OnCustomEvent(Caller);
    }
}

Setting a break point inside the condition in ASomeActor::SomeFunction(), I can clearly see that I’m getting a valid instance of UMyCustomObject, and I’m triggering the function OnCustomEvent() without any exceptions. Everything seems to work this far.

Blueprint
Coming to the blueprint inheriting from UMyCustomObject, I’m listening on the event to be fired, and simply want to log a message to the screen.

Again, pretty simple. Nothing fancy is going on.

Problem & expectations
I’d expect two things to happen:

  1. I’d see the message Hwllo from Blueprint on the screen during gameplay
  2. I’d hit the breakpoint in the blueprint

None of the above happens. The event is not fired all the way to the blueprint. I have absolutely no idea why this isn’t working, and I cannot figure it out.

Am I missing something? Shouldn’t I be able to fire events on custom UObject’s, or have I misunderstood something?

Any help on the issue is highly appreciated.

Thank you in advance.

Bonus info
Instead of UFUNCTION(BlueprintImplementableEvent), I’ve tried with BlueprintNativeEvent as well as a default C++ implementation:

/** .h */
UFUNCTION(BlueprintNativeEvent)
void OnCustomEvent(ACharacter* Caller);

/** .cpp */
void UMyCustomObject::OnCustomEvent_Implementation(ACharacter* Caller)
{
    UE_LOGFMT(LogMyCustom, Display, "Hello from C++");
}

In this scenario, I can easily find the message "Hello from C++" in my logs, but the event still isn’t fired on the blueprint. I’m still not hitting the breakpoint on my Print String, and still no message is displayed on the screen during gameplay.

Alright, I managed to solve the issue myself.

When creating the new custom UObject, if I were to add the outer (NewObject<UMyCustomObject(this, CustomObject)>) everything seems to work as expected.

That makes the entire caller ASomeActor::SomFunction look like this:

void ASomeActor::SomeFunction(ACharacter* Caller, TSubclassOf<UMyCustomObject> CustomObject)
{
    if(CustomObject)
    {
        // Simple UObject creation.
        UMyCustomObject* MyObject = NewObject<UMyCustomObject>(this /*<---*/, CustomObject);

        // Fire the event.
        MyObject->OnCustomEvent(Caller);
    }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.