How to call Blueprint CustomEvent from C++

[What I want to do]
Hi, I’m Irying call Blueprint CustomEvent function from C++.

Note that we want to do this without using BlueprintImplementable or BlueprintNativeEvent.

image

[What I tried]

UFunction* Function = MyClassInstance->GeneratedClass->FindFunctionByName(FunctionName);
MyClassInstance->ProcessEvent(Function, nullptr);

this code caused error.

Assertion failed: ((UObject*)ContainerPtr)->IsA(GetOwner<UClass>()) [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Public\UObject\UnrealType.h] [Line: 487] 'BP_MyClass' is of class 'MyClass' however property 'UberGraphFrame' belongs to class 'MyClass_C'

thank you in advance.

What is MyClassInstance ?

MyClassInstance is my own asset that inherits from the UBlueprint class.

I have these own asset.
There is a node I created.
From that node I am trying to call CustomEvent in EventGraph from C++.

CustomEvents are automatically created on the EventGraph when the user double-clicks on a node and have an internal relationship.

When the asset is executed during the game, it will transition from the Start node through the Message node to the End node.

I’m trying to execute a CustomEvent from C++ that has a relationship with a node at runtime.

There’s no variable GeneratedClass in UObject so I’m curious what is the type of MyClassInstance.
Can you show the full C++ function, or at least its signature ?

The way I see it, variable MyClassInstance should be of type MyClass*, and the code should rather look like

UFunction* Function = MyClassInstance->FindFunction(FunctionName);

Sorry, I sent you a blank message.

UCLASS(Blueprintable, BlueprintType)
class PTOTALKSYSTEM_API UPtoTalkInstance : public UBlueprint
{
	GENERATED_UCLASS_BODY()
public:
	// ~~~~~~
};

Of course, I’m trying FindFunction.
FindFunction could not find CustomEvent on EventGraph.

You must extend UObject not UBlueprint.

UCLASS(Blueprintable, BlueprintType)
class PTOTALKSYSTEM_API UPtoTalkInstance : public UObject
{
    GENERATED_UCLASS_BODY()
public:
    UFUNCTION(BlueprintCallable)
    void CallFunction(FName FunctionName)
    {
        if (UFunction* Func = FindFunction(FunctionName))
            ProcessEvent(Func, nullptr);
    }

    // or a static variant
    UFUNCTION(BlueprintCallable)
    static void CallFunction(UObject* Obj, FName FunctionName)
    {
        if (Obj)
        {
            if (UFunction* Func = Obj->FindFunction(FunctionName))
                Obj->ProcessEvent(Func, nullptr);
        }
    }
};

Calling it with an instance of NewPtoTalkInstance and “Message_1_0” should work fine.

I am sorry for the delay.
Thank you very much. Problem solved.

First.
I made the derived from UObject instead of from UBlueprint.
image

However, EventGraph(UbergraphPages?) cannot be accessed from MyClassInstance (derived from UObject), I created a MyClassBlueprint (derived from UBlueprint) separate from MyClassInstance.
(Maybe the interpretation is wrong.)
image

Next, I set UMyClassInstance::StaticClass to ParentClass in MyClassBlueprintFactory.

This way, when MyClassBlueprint is created in the editor, ParentClass becomes MyClassInstance and the class in BlueprintEditor becomes MyClassBlueprint.

As a result, I can call CustomEvent of Blueprint’s EventGraph in C++ through MyClassInstance at the execution of my own node.

thank you d(・_・)b

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